首页 > sql server 统计某列中某个数据出现频率

sql server 统计某列中某个数据出现频率

sql小白,数据库 sql server2008
问题1:
table表中有列cswhdxs,统计其中功能建议的数量及占比,

求得到这样的表:

cswhdxs总数 功能建议数量 占比
100 1 1%

问题2:
统计表中同一名字对应不同版本号的数量,并按数量排序。查询得到下表:

名称 版本号 数量
xxxx 11111 5
xxxx 22222 5
yyyy 11111 6
yyyy 22222 7
zzzz 11111 8
zzzz 22222 9


问题1:

select t2.total, t1.cswhdxs, count(t1.cswhdxs) num, (100*count(t1.cswhdxs))/t2.total percentage
from table t1, (select count(*) total from table) t2
group by t2.total, t1.cswhdxs

问题1
select concat(cast(coalesce(round(x/y,2),0)*100 as char),'%') from table

问题2 我给你个思路吧
条件用 WHEN
统计版本用count()
按数量排序用 ORDER BY


问题2

select 名称,版本号,count(*) as 数量 from table group by 名称,版本号 order by 数量 asc
【热门文章】
【热门文章】