谁能帮我查询?
我尝试了以下方法,但出现错误
SELECT Column1, Column2, Column3 FROM Table WHERE [Column1] NOT IN
(SELECT [Column1] FROM Table GROUP BY [Column1] HAVING COUNT([Column]) > 1)
子查询 [Column1] 中的 MEMO、OLE 或超链接对象无效。
谁能帮我查询?
我尝试了以下方法,但出现错误
SELECT Column1, Column2, Column3 FROM Table WHERE [Column1] NOT IN
(SELECT [Column1] FROM Table GROUP BY [Column1] HAVING COUNT([Column]) > 1)
子查询 [Column1] 中的 MEMO、OLE 或超链接对象无效。
使用Group By
withHaving
子句:
SELECT Column1, MIN(Column2)AS Column2, MIN(Column3)AS Column3
FROM dbo.Table
GROUP BY Column1
HAVING ( COUNT(Column1) = 1 )
应该可以工作,因为每个“组”只有一行。
您的原始查询应该可以工作,您只有 column 而不是 column1。
SELECT Column1, Column2, Column3 FROM TableName WHERE [Column1] NOT IN
(SELECT [Column1] FROM TableName GROUP BY [Column1] HAVING COUNT(Column1) > 1)
据我所知,您需要 [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 )