日期:2014-05-18 浏览次数:20813 次
select'A' name ,'a' [Type] into #tmp union select'B','a' union select'C','b' union select'D','b' select [Type], str(count(*) * 100/ (select count(*) from #tmp)) +'%' as scale from #tmp group by [type] drop table #tmp
------解决方案--------------------
Access下测试成功:
select [Type],count(*)/(select count(*) from ex)*100&'%' as scale from ex group by [Type]
SQL Server下可能要把连接字符的&改成+吧,试下这个
select [Type],count(*)/(select count(*) from ex)*100+'%' as scale from ex group by [Type]
------解决方案--------------------
select type,concat(to_char(count(name)/(select count(*) from T)*100),'%') from T group by type
------解决方案--------------------
select distinct Type,cast((100.*COUNT(1) over(partition by Type)/COUNT(1) over()) as varchar(20))+'%' as scale from 表T;