查询一个表某列 的 项的 相同项的百分比

NeedleStick 表中 Job列里面的数据项 ,相同项的个数,以及百分比:

 

 

select Job, count(Job),convert(varchar,(convert(float,count(Job))/convert(float,(select count(Job) from NeedleStick)))*100) +'%'  from NeedleStick group by Job having Job <> ''

 

 

如果要让百分比 保留两位小数 :

 

select Job, count(Job),convert(varchar,convert(decimal(10,1),(convert(float,count(Job))/convert(float,(select count(Job) from NeedleStick)))*100))+'%' from NeedleStick group by Job having Job <> ''

posted on 2009-05-08 10:19  tongdengquan  阅读(105)  评论(0编辑  收藏  举报