猿问

Mysql子查询问题

select school_id,count(stu_sex) as scount from stu where (school_id,count(stu_sex)) =(select school_id ,count(stu_sex) as count from stu group by school_id order by count desc limit 1) group by stu_sex;

提示: Utilisation invalide de la clause GROUP,这是啥意思?


qq_天蝎的尾巴卍_0
浏览 1453回答 3
3回答

KevenHuang

写这么复杂的sql语句,如果有实际需求而且不影响性能的情况尚可,但是如果性能很差,这样的sql语句必然会被诟病,所以,如果没有实际项目需求,这种sql语句一定要尽量避免,再者,有可能自己都看不懂,扰乱自己的思维。

慕粉1003216417

select school_id,count(stu_sex) as scount   from stu -- where (school_id,count(stu_sex)) =(select school_id ,count(stu_sex) as count from stu group by school_id order by count desc limit 1) group by stu_sex;把where条件先注释掉,你就发现你写的已经错了,简单查询先写好,再加where条件,还有,两个字段组合的等值写法是没有的,你可以试试用left join

泷一4229703

应该是group by的用法是错误的,你这查询太复杂。
随时随地看视频慕课网APP

相关分类

MySQL
我要回答