0
select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;);
私はあなたがwhere
句で集計関数を使用することはできませんMYSQL 5.7この構文で何が問題になっていますか?
select count(*),snum from enrolled group by snum where count(*)=(select count(distinct(cname)) from enrolled;);
私はあなたがwhere
句で集計関数を使用することはできませんMYSQL 5.7この構文で何が問題になっていますか?
を使用しています。
select count(*), snum
from enrolled
group by snum
having count(*) = (select count(distinct cname) from enrolled);
はまた、唯一のセミコロンは、クエリの最後に、表示されることがあります。あなたはhaving
句をしたいです。また、これは構文エラーではありませんが、distinct
は関数ではないため、かっこは必要ありません。
where
句に集計用語を使用することはできません。代わりに、having
句を使用する必要があります。
SELECT COUNT(*), snum
FROM enrolled
GROUP BY snum
HAVING COUNT(*) = COUNT(DISTINCT(cname))