Just a blog
分类: 数据库开发技术
2011-05-04 14:53:06
----集中度查询
1,分组,该组数据60%以上出现的值进行显示,否则不显示
2,值的小数只保留一位
select name,value_cut,pct,left(convert(varchar,value_cut),convert(int,(pct/0.6))*18) Percent60
--replace(convert(varchar,convert(int,(pct/0.6))*value),'0','') as Percent60 convert(decimal(13.1),value)
from
(
select T1.name,value_cut,count_gro_nv,count_gro_n,
convert(decimal(4,2),(convert(decimal(4,2),count_gro_nv)/count_gro_n)) pct
from(
select name,value_cut,count(value_cut) count_gro_nv
from(
select name,convert(decimal(13,1),value) value_cut
from(--自测数据
select '01' Code,'A' name,1 value
union select '02','A',2
union select '03','A',3
union select '04','A',3
union select '05','A',3
union select '06','A',3
union select '07','B',123456789012.999997
union select '08','B',123456789012.999998
union select '09','B',123456789012.999999
) T0
) TT group by name,value_cut
) T1 left join
( select name,count(value_cut) count_gro_n
from(
select name,convert(decimal(13,1),value) value_cut
from(--自测数据
select '01' Code,'A' name,1 value
union select '02','A',2
union select '03','A',3
union select '04','A',3
union select '05','A',3
union select '06','A',3
union select '07','B',123456789012.999997
union select '08','B',123456789012.999998
union select '09','B',123456789012.999999
) T0
) TT group by name
) T2 on T1.name=T2.name
) TA