日期:2014-05-17 浏览次数:20416 次
select c.sid,sum(case when 功能 = 1 then 1 else 0 end ) as '开通1号功能的人数', sum(case when 功能 = 2 then 1 else 0 end ) as '开通2号功能的人数', count(s.sid) as '登录人数' from city c left join student s on c.sid= s.sid group by c.sid
------解决方案--------------------
SELECT 城市表.Ssdm Sid,
COUNT(学生表.Sname) Stu_Num,
SUM(CASE
WHEN 字段开通1号 THEN 1 ELSE 0
END) A1_Num,
SUM(CASE
WHEN 字段开通2号 THEN 1 ELSE 0
END) A2_Num,
COUNT(学生表.Loginnum) Log_Num
FROM 学生表, 城市表
WHERE 城市表.Ssdm = 学生表.Ssdm
GROUP BY 城市表.Ssdm