select s_id, s_name, s_sex
from student
where s_id in (select s_id
from score
group by s_id
having c_id in (select c_id #这里有问题
from score
where s_id = 01)
and count(c_id) = 3)
and s_id != 01;
执行时报错
ERROR 1054 (42S22) at line 1 in file: 'src1/step2/query2.sql': Unknown column 'c_id' in 'IN/ALL/ANY subquery'
但是单独执行下面的语句的时候,能正常显示出c_id
select c_id
from score
where s_id = 01;
结果如下
+------+
| c_id |
+------+
| 01 |
| 02 |
| 03 |
+------+
https://www.educoder.net/task...这上面的一个题目
我还是不理解,如果在having中单独使用的话,而不是通过聚类函数,一定也要在select出现
select s_sex, s_name #这里没有s_name就报错
from student
group by s_sex
having s_name != 'Mia';
select s_sex #这条语句执行正常
from student
group by s_sex
having count(s_name) > 0;