通过表student_1
cid name gender class
301 neleson man 1
302 apple femal 2
303 king man 1
304 wang man 3
查询出以下语句:
class boy gril count
1 2 0 2
2 0 1 1
3 1 0 1
但是偶不知道是不是该用外连接(用了老报错)所以结果老是不出现class=2的行
[大师们帮帮偶啊 偶都调试一天了啊 我用的 MYSQL ]select a.class,b.man,c.count-b.man gril,c.count from
student_1 as a,
(select count(*) man,class from student_1 where gender='man' group by class) as b,
(select count(*) count,class from student_1
group by class) as c
on a.class = c.class
where a.class = c.class and c.class = b.class
group by class
cid name gender class
301 neleson man 1
302 apple femal 2
303 king man 1
304 wang man 3
查询出以下语句:
class boy gril count
1 2 0 2
2 0 1 1
3 1 0 1
但是偶不知道是不是该用外连接(用了老报错)所以结果老是不出现class=2的行
[大师们帮帮偶啊 偶都调试一天了啊 我用的 MYSQL ]select a.class,b.man,c.count-b.man gril,c.count from
student_1 as a,
(select count(*) man,class from student_1 where gender='man' group by class) as b,
(select count(*) count,class from student_1
group by class) as c
on a.class = c.class
where a.class = c.class and c.class = b.class
group by class
解决方案 »
- 请问为什么MySQL导出的sql里的表格先后顺序不受外键限制?
- 高并发和要求安全性高的项目用mysql哪个版本最合适?
- Mysql存储过程怎么跳出死循环While语句的方法。
- 设计一个备份系统,我的想法和问题 请大家给指点
- FORCE INDEX 无效,没有使用索引求解!
- 郁闷!!
- 紧急求救!!!!
- 通过select建临时表和指定primary key 可以一条语句完成吗?
- mysql_library_init在winows7英文系统下失败!
- Order by 以字段序号来排序,单不知道字段名
- 一个sql,insert语句中如果有中文就会出错,怎么回事儿呢?
- 请问MYSQL使用LOAD时如何跳过数据格式错误的行
(select class,count(class) as total from student_1 group by class)a left join
(select class,count(class) as boy from student_1 where gender='male' group by class)b on a.class=b.class
left join
(select class,count(class) as boy from student_1 where gender='female' group by class)c on a.class=c.class;