Microsoft当前允许使用此语法。
SELECT *
FROM ( VALUES (1) ) AS g(x)
WHERE EXISTS (
SELECT *
FROM ( VALUES (1),(1) )
AS t(x)
WHERE g.x = t.x
HAVING count(*) > 1
);
请注意,GROUP BY
该EXISTS
子句中没有有效的ANSI SQL。还是仅公开实现细节。
作为参考,PostgreSQL不允许使用相同的语法。
错误:“ tx”列必须出现在GROUP BY子句中或在聚合函数中使用
但是允许使用此语法。
SELECT *
FROM ( VALUES (1) ) AS g(x)
WHERE EXISTS (
SELECT 1 -- This changed from the first query
FROM ( VALUES (1),(1) )
AS t(x)
WHERE g.x = t.x
HAVING count(*) > 1
);
并且允许使用此语法。
SELECT *
FROM ( VALUES (1) ) AS g(x)
WHERE EXISTS (
SELECT *
FROM ( VALUES (1),(1) )
AS t(x)
WHERE g.x = t.x
GROUP BY t.x -- This changed from the first query
HAVING count(*) > 1
);
问题来自与@ErikE的聊天对话