开发者

Find IDs where another column has at least two distinct values

开发者 https://www.devze.com 2023-01-26 03:57 出处:网络
I have this: SELECT DocumentID FROM ( SELECT DocumentID, Extension FROM Pages GROUP BY DocumentID, Extension HAVING ( Count(1) > 2 )

I have this:

SELECT DocumentID
FROM
(
SELECT DocumentID, Extension FROM Pages
GROUP BY DocumentID, Extension HAVING ( Count(1) > 2 )
) MultiplePages
GROUP BY MultiplePages.D开发者_开发知识库ocumentID Having ( Count(1) > 1 )

I am looking for a result set of Documents that have multiple pages where the pages do not share a distinct extension. This query works but I was wondering if there was a better way.

Also, I am new to Stack Overflow and I am open to suggestions on creating better titles, descriptions, or how I might have searched for this question. Thanks.


SELECT DocumentID
FROM Pages
GROUP BY DocumentID
HAVING COUNT(DISTINCT(Extension)) > 1

or

SELECT DocumentID
FROM Pages
GROUP BY DocumentID
HAVING MIN(Extension) <> MAX(Extension)
0

精彩评论

暂无评论...
验证码 换一张
取 消