求助 统计的sql语句 求个sql语句ID 类别1 A 2 A 3 A 4 B 5 B 6 B 7 C 8 A 9 D 10 C如何知道各个类别占总数的百分比 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select 类别,count(1)*1.0/count(1)over() from tb group by 类别 select [类别],count(1)/(select count(1) from [表])from [表]group by [类别] select [类别],ltrim(count(1)/(select count(1) from [表]))+'%' as 百分比from [表]group by [类别] 这个结果好像有问题 我想要的结果是A 40% B30% C20% D10% select [类别],ltrim(cast(count(1)*100./(select count(1) from [表]) as decimal(6,2)))+'%' as 百分比from [表]group by [类别] select 类别,ltrim(cast(count(1)*100.0/count(1)over() as decimal(6,2))) + '%' as [百分比]from tb group by 类别 select [类别],ltrim(cast(count(1)*100.0/(select count(1) from [表]) as decimal(18,2)))+'%' as 百分比from [表]group by [类别] 如何设置默认的数据库引擎?期待中。。。。 dts包失败问题 怎么在left join的时候进行group by?请高手帮忙 SQL 2000 库文件过大优化问题 sql server 2005 存储过程 基础 怎么把在查询分析器里面查到的数据导出成ACCESS这类或者简单的格式,,不想要*rtp的,呵呵,在线等 怎么样才能把SQL SERVER卸载干净? 查询数据量的语句 请教数据库文件突然增大的问题! SQL SERVER 2000的导出功能生成的表和手工建的表有差别吗? mysql导入问题,探究 SQL2005修改数据库记录时不能添加中文?
from [表]
group by [类别]
[类别],ltrim(count(1)/(select count(1) from [表]))+'%' as 百分比
from
[表]
group by
[类别]
这个结果好像有问题 我想要的结果是A 40% B30% C20% D10%
select
[类别],ltrim(cast(count(1)*100./(select count(1) from [表]) as decimal(6,2)))+'%' as 百分比
from
[表]
group by
[类别]
select 类别,ltrim(cast(count(1)*100.0/count(1)over() as decimal(6,2))) + '%' as [百分比]
from tb
group by 类别
[类别],ltrim(cast(count(1)*100.0/(select count(1) from [表]) as decimal(18,2)))+'%' as 百分比
from
[表]
group by
[类别]