我有以下 SQL 查询,但这不是我想要的:
SELECT
TOP (20) Attribs.ImageID AS ItemID
FROM
Attribs
LEFT OUTER JOIN
Items ON Attribs.ImageID = Items.ImageID
WHERE
(attribID IN ('a','b','c','d','e'))
AND (deleted NOT IN (1,2))
AND Attribs.attribID = 'a' AND Attribs.attribID = 'b'
GROUP BY
Attribs.ImageID
ORDER BY
COUNT(DISTINCT attribID) DESC
我需要的是查询
AND Attribs.attribID = 'a' AND Attribs.attribID = 'b'
首先,然后是基于上述查询结果的 WHERE 子句的其余部分。
这可以使用子查询来实现吗?
我正在使用 SQL Server 2008
谢谢