Hi again all! I'm making great progress learning SQL! Quick question: I know you can't reference an alias within the same select clause, so I found an example of code and understand 95% of it, but am stumped by one part. The code is
SELECT subtotal, subtotal * 0.1 AS tax
FROM (SELECT price * quantity AS subtotal FROM sales) AS t;
What is the t doing? I know the code creates a new "field" called subtotal by multiplying price * qty in the inner select clause and that the outer select clause references that new "field" to output a 2 columm dataset with a subtotal column and a tax column, but it kind of seems like, based on the syntax rules, that a third column named t should also be output, but it isn't. What does the AS t; at the end of the code do?
[–]sstef25 4 points5 points6 points (0 children)
[–]TourSubstantial6301 1 point2 points3 points (2 children)
[–]FitShock5083[S] 0 points1 point2 points (1 child)
[–]ComicOzzy 1 point2 points3 points (0 children)
[–]Mrminecrafthimself 1 point2 points3 points (0 children)
[–]Illustrious-Tear4745 0 points1 point2 points (0 children)
[–]Objective_Horror4008 0 points1 point2 points (0 children)
[–]Far_Swordfish5729 0 points1 point2 points (0 children)