0

我尝试在 SQL Server 2012 中运行以下指令:

SELECT ID, Title
from Movies
where categoryID = 1 and (MovieID,1) in 
        (select MovieID, count(ID)
            from Copies
            group by (MovieID))

但是会抛出以下错误消息:

* 消息 4145,级别 15,状态 1,第 3 行在预期条件的上下文中指定的非布尔类型表达式,靠近“,”。*

我知道这个查询在 PostgreSQL 中运行得很好。为了在 SQL Server 2012 中正常运行,我应该进行哪些更改?

4

2 回答 2

2

您应该能够使用标准连接语法来做到这一点:

SELECT m.ID, m.Title
FROM Movies m
INNER JOIN (
        SELECT c.MovieID FROM Copies c GROUP BY c.MovieID HAVING COUNT(*) = 1
    ) cc ON m.MovieID = cc.MovieID
WHERE m.categoryID = 1
于 2013-10-31T22:05:31.217 回答
0
SELECT m.ID, m.Title
from Movies m
where m.categoryID = 1 
and 1 = (select count(*)
         from copies c
         where c.MovieID = m.MovieID);
于 2013-10-31T23:13:15.200 回答