简体   繁体   English

两列之和,只显示第三列

[英]The sum of two columns and only show the third column

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).我正在尝试编写并执行 SQL 查询,该查询返回具有最高“分数”的前三个记录,其中“分数”是两列的总和(我们称它们为 X 和 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.我得到了正确的答案,但我只想要得分列,而不是 x 和 y 列。 Done. XY 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.给出 3 列,因为你有 SELECT 3 件事。 Instead just SELECT what you need in your case,而不是 SELECT 你需要什么,

SELECT (X + Y) as score from survey
ORDER BY score DESC
LIMIT 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM