日期:2014-05-18 浏览次数:20407 次
--测试数据 create table Class(Stu_Name nvarchar(10),man bit,woman bit,Stu_city nvarchar(10)) insert into Class select '雷超',1,0,'洛阳' union select '雷超',0,1,'郑州' union select '杨泓',1,0,'兰州' union select '杨泓',0,1,'邯郸' union select '杨泓',1,0,'南通' --查找语句 select Stu_Name as '姓名' ,sum(case man when 1 then 1 else 0 end) as '男性人数' ,sum(case woman when 1 then 1 else 0 end) as '女性人数' from dbo.Class group by Stu_Name
------解决方案--------------------