这是我试图执行的代码:
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 程序i.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
但您还需要表名以避免歧义并使用显式连接语法
关于mysql - 如何解决 HAVING COUNT DISTINCT 附近的错误语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48646392/