求一个sql统计语句 name type(a/b/c)1012 a1012 b1013 a1013 a1014 c求一个sql语句查出每个name对应的type的a类有多少个,b类有多少,c类有多少 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试下面的语句:select name, sum(if(type = 'a', 1, 0)) as 'a', sum(if(type = 'b', 1, 0)) as 'b', sum(if(type = 'c', 1, 0)) as 'c',from 你的表group by name 上面多了个逗号……:select name, sum(if(type = 'a', 1, 0)) as 'a', sum(if(type = 'b', 1, 0)) as 'b', sum(if(type = 'c', 1, 0)) as 'c'from 你的表 group by name select name as a,type as b,(select count(*) from test2 where name=a and type=b) from test2 group by name,type select name ,type ,(select count(*) from test2 where name=a.name and type=a.type) from test2 a group by name,type select name,type,count(*)from tb group by name,type mysql怎么插入“SAINT BARTHÉLEMY” 求Liunx下的图形界面工具 LEFT JOIN查询时,WHERE语句作用于哪张表? 关于mysql插入“—”这个符号后,就报错的问题。[ mysql 时间转换的问题 关于按字母排序 mysql以及postgresql怎样才能实现大小写敏感? mysql数据库。 这样的操作sql该怎么写? MYSQL在win2000server的连接; 在数据库中删除特定字串 mysql c api 报错 Commands out of sync mysql case 中文显示乱码
name,
sum(if(type = 'a', 1, 0)) as 'a',
sum(if(type = 'b', 1, 0)) as 'b',
sum(if(type = 'c', 1, 0)) as 'c',
from 你的表
group by name
name,
sum(if(type = 'a', 1, 0)) as 'a',
sum(if(type = 'b', 1, 0)) as 'b',
sum(if(type = 'c', 1, 0)) as 'c'
from 你的表 group by name
select name as a,type as b,(select count(*) from test2 where name=a and type=b) from test2 group by name,type
select name ,type ,(select count(*) from test2 where name=a.name and type=a.type) from test2 a group by name,type
from tb
group by name,type