读书人

非常急问一个比较简单的有关问题,思路

发布时间: 2012-01-18 00:23:26 作者: rapoo

非常急,在线等,问一个比较简单的问题,思路不清楚,急~~~~~~~~~~~~
做一个分类(比重)的统计

举个例子,统计结果是这样
月卡问题 38 5%
意见建议 22 1%
无法连接 66 10%

我自己写的语句
select t.name,_________
from T_Question q inner join T_Questiontype t
on t.id=q.qtid
group by t.name

备注:Question表里的qtid是外键,主键是问题类型表(T_Questiontype)里的id


问题:下划线那里加什么,经理对我说是每一类问题的数量除以所有问题的总数,我就不知道怎么写了,今天下午全晕了

高手帮忙,如果我做的思路错了请指出来

[解决办法]
try

select t.name, Count(t.name) As 统计结果, Count(t.name) * 1.0 / (Select Count(*) From T_Question)
from T_Question q inner join T_Questiontype t
on t.id=q.qtid
group by t.name
[解决办法]
举个例子,统计结果 百分比
月卡问题 38 5%
意见建议 22 1%
无法连接 66 10%

select t.name,cal=统计结果/(cast(replace(百分比, '% ', ' ') as int)/100)
from T_Question q inner join T_Questiontype t
on t.id=q.qtid
group by t.name
[解决办法]

select t.name,sum(select count(1) from t_question where t.id=id)/count(1) as rate
from T_Question q inner join T_Questiontype t
on t.id=q.qtid
group by t.name

读书人网 >SQL Server

热点推荐