通过表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
(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;