sql语句问题,高手请进
例如一个表中有多个种类的东西,每个种类又分1,2两种情况,统计每个种类这两种情况各是多少
用sql统计,有什么好的解决方案么
[解决办法]
- SQL code
select "种类", sum(case when "子类" = '1' then 1 else 0 end) as "子类1次数", sum(case when "子类" = '2' then 1 else 0 end) as "子类1次数" from tbl group by "种类";
发布时间: 2012-01-14 20:02:35 作者: rapoo
sql语句问题,高手请进
例如一个表中有多个种类的东西,每个种类又分1,2两种情况,统计每个种类这两种情况各是多少
用sql统计,有什么好的解决方案么
[解决办法]
select "种类", sum(case when "子类" = '1' then 1 else 0 end) as "子类1次数", sum(case when "子类" = '2' then 1 else 0 end) as "子类1次数" from tbl group by "种类";