Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBoban Talevski
24,793 PointsIs there a way to write the query as shown in the video without hardcoding the values of LocationID?
In this example, we knew upfront how many locations we had and manually picked the IDs of those locations in order to create exactly 2 subqueries.
I'm curious to know if there is a way to actually tell SQL something along these lines: Hey, get the locations from the Location table, create as many subqueries as the number of locations, use the appropriate LocationID in the WHERE clause of each subquery, alias each subquery with LocationName || "Amount", and add all these columns in the main query.
Just so the query will work regardless of how many locations we have in our database.
I'm assuming it depends of the actual SQL implementation and involves PLSQL or T-SQL programming for Oracle and MSSQL for example, or are these "SQL programming extensions" (or w/e they are called) not intended for this kind of thing?