在Sql Select Query中如何在一个查询中选择最大三个值 [英] In Sql Select Query how to select max three value in one query

查看:148
本文介绍了在Sql Select Query中如何在一个查询中选择最大三个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有这样的桌子

id名称百分比
1个40
2 b 60
3 c 60
4 d 60
5 e 50
6楼70
8克80

在此表中,我想选择最多三个百分比,然后我要为该三个最大百分比选择名称,对于相同百分比,该三个最大百分比的名称超过一次
请建议
在此先感谢

解决方案

select top 3 id, name, percent from mytable order by percent desc


尝试一下:

 选择 *
来自 MyTable a
其中(选择 count(不同 [百分比]) MyTable中的> 百分比]> = a.[百分比])< = 3 


hi
I have a table like this

id Name Percent
1 a 40
2 b 60
3 c 60
4 d 60
5 e 50
6 f 70
8 g 80

In this Table i want to select max three percentage and after that the i want to select the name for that that three max percentage which has name more than one time for same percentage
pls suggest
thanks in advance

解决方案

select top 3 id, name, percent from mytable order by percent desc


Try this:

select  *
from    MyTable a
where   (select count(distinct [Percent]) from MyTable where [Percent]>=a.[Percent])<=3


这篇关于在Sql Select Query中如何在一个查询中选择最大三个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆