select top 10 A from table order by A desc
将A列从大到小排序,取出前十行数据
select * from table where A in (
select top 10 A from table order by A desc
)
将所有A列数值等于取出最大十个数值的数据全部查找出来
select top 10 A from (select distinct A from table )T order by A desc
将A列数值去除重复值,然后从大到小排序,取出不重复的前十行数据
select * from table where A in (
select top 10 A from (select distinct A from table )T order by A desc
)
将所有A列数值等于取出最大十个数值的数据全部查找出来
换一个角度去理解问题可以吗?
你查找的排序好的最大值,就把它当做id处理好了,
查找方式就是与大于或等于top 10 里面的数值都找出
select tb_score.score from tb_score where //查询分数,从表tb_score
tb_score.score //条件--查询的分数不在某个区域里面
not in(
select tb_score.score from tb_score where //查询分数,从某个区域中
tb_score.score
order by score desc)
)
order by tb_score.score desc
步骤就是:先取出前10个分数(top 10),然后得出小于前10的有哪些(
楼主说的应该是SQL Server的写法吧?
SQL Server TOP子句提供了ties关键字可以实现你的需要
SELECT TOP 10 WITH TIES * FROM table1 ORDER BY A DESC
select * from table where A in (select top 10 A from table order by A)
select top 10 a from table order by a desc