这是我试图执行的代码:

SELECT ID_K
FROM koncert,
     programi
WHERE koncert.ID_K = programi.ID_K
GROUP BY koncert.ID_K
HAVING COUNT (DISTINCT programi.Salla) = 2


它返回此错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to
your MariaDB server version for the right syntax to use
near 'DISTINCT programi.Salla)=2 LIMIT 0, 25' at line 4.


试图改变不同的东西,但仍然无法进行。

最佳答案

您应该使用count(DISTINCT programi.Salla
)而不计算(..)..删除COUNT和(...之间的空格

SELECT koncert.ID_K
FROM koncert
INNER JOIN    programi  on koncert.ID_K = programi.ID_K
GROUP BY koncert.ID_K
HAVING COUNT(DISTINCT programi.Salla) = 2


但是您还需要表名以避免歧义,并且也使用显式联接sintax

关于mysql - 如何在HAVING COUNT DISTINCT附近解析错误的语法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48646392/

10-13 06:54