Mysql 什么';这个语法怎么了?

Mysql 什么';这个语法怎么了?,mysql,sql,Mysql,Sql,我使用的是MYSQL 5.7您不能在where子句中使用聚合函数。您需要一个具有子句: select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;); select count(*), snum from enrolled group by snum having count(*) = (select count(distinct c

我使用的是MYSQL 5.7

您不能在
where
子句中使用聚合函数。您需要一个
具有
子句:

select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;);
select count(*), snum
from enrolled
group by snum 
having count(*) = (select count(distinct cname ) from enrolled);

此外,查询结束时只能显示一个分号。而且,尽管这不是语法错误,
distinct
不是函数,所以它不需要括号

不能在
where
子句中使用聚合函数。您需要一个
具有
子句:

select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;);
select count(*), snum
from enrolled
group by snum 
having count(*) = (select count(distinct cname ) from enrolled);

此外,查询结束时只能显示一个分号。而且,尽管这不是语法错误,
distinct
不是函数,所以它不需要括号

不能在
where
子句中使用聚合术语。相反,您应该使用
having
子句:

select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;);
select count(*), snum
from enrolled
group by snum 
having count(*) = (select count(distinct cname ) from enrolled);

不能在
where
子句中使用聚合术语。相反,您应该使用
having
子句:

select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;);
select count(*), snum
from enrolled
group by snum 
having count(*) = (select count(distinct cname ) from enrolled);