name type(a/b/c)
1012 a
1012 b
1013 a
1013 a
1014 c
求一个sql语句查出每个name对应的type的a类有多少个,b类有多少,c类有多少
1012 a
1012 b
1013 a
1013 a
1014 c
求一个sql语句查出每个name对应的type的a类有多少个,b类有多少,c类有多少
解决方案 »
- mysql数据库 表中的字段类型 为什么会无缘无故的自动改变呢?
- 求一个函数 sql 选择集合中第二小
- mysql表之间的对比更新
- 一道sql面试题,各位请帮忙看看
- Thread stack overrun(mysql)急就送100分
- mysql字符界面使用问题
- 行集保存起来到一个数据结构
- 有没有比较适合mysql5.0的客户端工具?
- Applet jdbc mysql
- java 连接Mysql java.net.SocketException: Software caused connection abort: socket
- 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