[英]SQL Server query, in order of higher number in a column
How would I write a query that only shows 10 pieces of data and only the highest number in the count column? 我该如何写一个仅显示10条数据并且在count列中仅显示最高编号的查询?
I'm thinking, 我在想,
SELECT *
FROM score
WHERE count = (SELECT MAX(count)
FROM score
WHERE count <> (SELECT MAX(count) FROM score) TOP 10;
I know I'm almost there just not quite. 我知道我几乎不在那里。
I am trying to show the top ten of the highest count from the score table. 我试图显示分数表中最高计数的前十名。
If you have the scores and just want to see them in order: 如果您有分数并且只想按顺序查看它们:
SELECT
top 10 count
FROM
score
order by count desc
To use an aggregate, you need to compare it against something. 要使用聚合,您需要将其与某些对象进行比较。 If you have users for example:
例如,如果您有用户:
SELECT
top 10 sum(count), u.userid
FROM
score s
inner join users u on s.userid = u.userid
group by u.userid
order by sum(count) desc
SELECT * FROM SCORE ORDER BY COUNT DESC TOP 10
Or wherever top 10
goes... will give top 10 scores. 或
top 10
走到哪里……都会给出前10名得分。
SELECT * FROM SCORE WHERE COUNT = (SELECT MAX(COUNT) FROM SCORE) TOP 10
Top 10 rows having score equal max count. 得分最高的前10行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.