关于数据分类汇总的sql 本帖最后由 newtypebao 于 2011-07-06 11:28:48 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select Name,sum(if(Type='type1',Price,0)),sum(if(Type='type2',Price,0)),sum(if(Type='type3',Price,0)) from tt group by Name 我编辑的时候格式还是好好的 怎么提交后格式就变这样了我再补充下吧。。数据就是每种Name的都有几种Type 并且每条数据都有个price汇总的数据是每种Name 每种Type 的price求和 select name,sum(case when type='type1' then price else 0 end) as SumType1Price,sum(case when type='type2' then price else 0 end) as SumType2Price from tbgrop by name 请问下如果我还要求每种type的count可以么count(if(Type='type2',*,0))这样貌似不行。。count(if(Type='type2',1,0))这样貌似也不行。。 count的话也是用sumsum(if(Type='type2',1,0)),也就是符合条件的行算1,不符合条件的行算0 请问下现在mysql哪个版本较好?目前最新为5.5.28 MySQL如何解决中文插入问题 MySQL 适用于中小规模应用? 急,求一个存储过程 两个表合成查询??? Postgresql的数组插入问题,请大家指点一下。 急问:一个 三表联合查询的问题(mysql) 关于MYSQL语句问题? delede删除同一张表格中两个不同字段值等的数据 mysql存储过程 mysql那种数据类型可以不在小数点后面自动补零 请教 PostgreSQL 创建收支平衡 视图 的方法
sum(if(Type='type2',Price,0)),sum(if(Type='type3',Price,0))
from tt group by Name
我再补充下吧。。
数据就是每种Name的都有几种Type 并且每条数据都有个price
汇总的数据是
每种Name 每种Type 的price求和
sum(case when type='type2' then price else 0 end) as SumType2Price
from tb
grop by name
请问下如果我还要求每种type的count可以么
count(if(Type='type2',*,0))
这样貌似不行。。
count(if(Type='type2',1,0))
这样貌似也不行。。
sum(if(Type='type2',1,0)),也就是符合条件的行算1,不符合条件的行算0