日期:2014-05-18  浏览次数:20340 次

这个查找语句怎么写?[之前发过一个但是我想错了]



我想查看的这3个是 SceneId,UsersSex = '男'的用户人数,UsersSex = '女'的用户人数。

补充说明一下UsersName是UsersInfo主键,还是ApplyInfo外键。SceneId是ApplyInfo外键

之前发过一个了 = = 求各位大神帮忙

------解决方案--------------------
try
SQL code
select b.SceneId,
  男用户人数=sum(case when a.UsersSex='男' then 1 else 0 end),
  女用户人数=sum(case when a.UsersSex='女' then 1 else 0 end)
from (select distinct SceneId,username from applyinfo) b
join usersinfo a on a.a.username=b.username
group by b.SceneId