0

谁能帮我查询?

我尝试了以下方法,但出现错误

SELECT Column1, Column2, Column3 FROM Table WHERE [Column1] NOT IN 
(SELECT [Column1] FROM Table GROUP BY [Column1] HAVING COUNT([Column]) > 1)

子查询 [Column1] 中的 MEMO、OLE 或超链接对象无效。

4

3 回答 3

4

使用Group BywithHaving子句:

SELECT Column1, MIN(Column2)AS Column2, MIN(Column3)AS Column3
FROM dbo.Table
GROUP BY Column1
HAVING ( COUNT(Column1) = 1 )

应该可以工作,因为每个“组”只有一行。

于 2012-11-14T15:23:25.597 回答
1

您的原始查询应该可以工作,您只有 column 而不是 column1。

 SELECT Column1, Column2, Column3 FROM TableName WHERE [Column1] NOT IN 
(SELECT [Column1] FROM TableName GROUP BY [Column1] HAVING COUNT(Column1) > 1)

见:http ://sqlfiddle.com/#!3/d99a8/5/0

于 2012-11-14T16:03:07.057 回答
0

据我所知,您需要 [Column1] 唯一的所有数据(仅出现一次)

DECLARE @x TABLE (col1 INT, col2 INT, col3 INT)

INSERT INTO @x
        ( [col1], [col2], [col3] )
VALUES  ( 1, 2, 3  )
        ,( 1, 4, 5 )
        ,( 2, 6, 7 )

SELECT * FROM @x

SELECT col1, col2 , col3 FROM @x
WHERE col1 NOT IN 
    ( SELECT [col1]  FROM @x GROUP BY [col1] HAVING  COUNT(*) > 1 )
于 2012-11-14T15:29:39.697 回答