select t1.col1,t2.col2,cast(cnt1/cnt2 as decimal(18,2)) from
(select col1,col2,col3,count(*) cnt1 from tb group by col1,col2,col3) t1,
(select col1,col2,count(*) cnt2 from tb group by col1,col2) t2
where t1.col1 = t2.col1 and t1.col2 = t2.col2
表名 tb
我觉得是:
col1 col2 col3
问卷1|问题1| 答案
问卷1|问题2| 答案
问卷1|问题3| 答案
--sql,t1,t2是表别名.
select t1.col1,t2.col2,cast(cnt1/cnt2 as decimal(18,2)) from
(select col1,col2,col3,count(*) cnt1 from tb group by col1,col2,col3) t1,
(select col1,col2,count(*) cnt2 from tb group by col1,col2) t2
where t1.col1 = t2.col1 and t1.col2 = t2.col2