求一条mysql查询语句

[复制链接]
查看11 | 回复4 | 2013-3-12 10:12:43 | 显示全部楼层 |阅读模式
SELECT CODE, SUM(IF(TYPE = 'a', 1, 0)) 'a的个数', SUM(IF(TYPE = 'b', 1, 0)) 'b的个数', SUM(IF(TYPE = 'c', 1, 0)) 'c的个数'FROM abcGROUP BY CODE...
回复

使用道具 举报

千问 | 2013-3-12 10:12:43 | 显示全部楼层
select code,sum(case type when 'a' then 1 else o end)as a的个数,sum(case type when 'b' then 1 else o end)as b的个数,sum(case type when 'c' then 1 else o end)as c的个数from table...
回复

使用道具 举报

千问 | 2013-3-12 10:12:43 | 显示全部楼层
select
code,
sum(case when type = a then 1 else 0 end) as a的个数,
sum(case when type = b then 1 else 0 end) as b的个数,
sum(case when type = c then 1 else 0 end)...
回复

使用道具 举报

千问 | 2013-3-12 10:12:43 | 显示全部楼层
德望喝了汤隔帘花影太厉害...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行