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

Asked By: runnergirl229

||

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
Answered By: Brijesh Varsani
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.