如何查询数据库里某个字段的某个值出现频率最高的前十个?
如:
日期 故障设备
3.01 a
3.02 b
3.03 c
3.04 a
3.05 c
3.06 a
3.07 d
请找出“故障设备”字段中最多的那个值
9 个解决方案
#1
select top 10 故障设备
from tb
group by 故障设备
order by count(1) desc
#2
select 故障设备,count(*) AS 频率 INTO #T FROM TB GROUP group by 故障设备
SELECT TOP 10 * FROM #T ORDER BY 频率 DESC
#3
select top 10 故障设备 ,count(*) 次数
from tb
group by 故障设备
order by count(*) desc
#4
select top 10 [故障设备] ,count(*) as [次数]
from tb
group by [故障设备]
order by count(*) desc
#5
select top 10 故障设备,count(*) 次数
from tb
group by 故障设备
order by count(*) desc
from tb
group by 故障设备
order by count(*) desc
#6
select top 10 故障设备
from tb
group by 故障设备
order by count(*) desc
from tb
group by 故障设备
order by count(*) desc
#7
select top 10 故障设备,COUNT(故障设备) as 次数 from #erp_jhh_zj_zlqx group by 故障设备
#8
select top 10 故障设备 ,count(*) 次数
from tb
group by 故障设备
order by count(*) desc
#9
select
top 10 [故障设备] ,count(1) as [次数]
from
tb
group by
[故障设备]
order by
count(1) desc
#1
select top 10 故障设备
from tb
group by 故障设备
order by count(1) desc
#2
select 故障设备,count(*) AS 频率 INTO #T FROM TB GROUP group by 故障设备
SELECT TOP 10 * FROM #T ORDER BY 频率 DESC
#3
select top 10 故障设备 ,count(*) 次数
from tb
group by 故障设备
order by count(*) desc
#4
select top 10 [故障设备] ,count(*) as [次数]
from tb
group by [故障设备]
order by count(*) desc
#5
select top 10 故障设备,count(*) 次数
from tb
group by 故障设备
order by count(*) desc
from tb
group by 故障设备
order by count(*) desc
#6
select top 10 故障设备
from tb
group by 故障设备
order by count(*) desc
from tb
group by 故障设备
order by count(*) desc
#7
select top 10 故障设备,COUNT(故障设备) as 次数 from #erp_jhh_zj_zlqx group by 故障设备
#8
select top 10 故障设备 ,count(*) 次数
from tb
group by 故障设备
order by count(*) desc
#9
select
top 10 [故障设备] ,count(1) as [次数]
from
tb
group by
[故障设备]
order by
count(1) desc