The sum of two columns and only show the third column
Question:
I am trying to write and execute the SQL query that returns the top three records with the highest "score", where the "score" is the sum of two columns (let’s call them X and Y). The result should have one column named score.
Here is what I did
%%sql
select X,Y,(X + Y) as score from survey
ORDER BY score DESC
LIMIT 3
I got the right answer but I only want the score column, not the x and y column too.
Done. X Y score 4 9 13 4 8 12 3 7 10
Answers:
SELECT X, Y, (X+Y) ...
gives the 3 columns since you have SELECT 3 things. Instead just SELECT what you need in your case,
SELECT (X + Y) as score from survey
ORDER BY score DESC
LIMIT 3
I am trying to write and execute the SQL query that returns the top three records with the highest "score", where the "score" is the sum of two columns (let’s call them X and Y). The result should have one column named score.
Here is what I did
%%sql
select X,Y,(X + Y) as score from survey
ORDER BY score DESC
LIMIT 3
I got the right answer but I only want the score column, not the x and y column too.
Done. X Y score 4 9 13 4 8 12 3 7 10
SELECT X, Y, (X+Y) ...
gives the 3 columns since you have SELECT 3 things. Instead just SELECT what you need in your case,
SELECT (X + Y) as score from survey
ORDER BY score DESC
LIMIT 3