1

我正在尝试仅将唯一值插入表中,但它不起作用。对于所有 6000 行,Securities 表中只有一个 LastDownload 值。但在我的查询中,我在@Temp 中得到了超过 6000 个重复值。我只想要一个值。我错过了什么?

DECLARE @Temp TABLE ( Info VARCHAR( 256 ) )

INSERT INTO @Temp
SELECT LastDownLoad
FROM Securities AS S
WHERE NOT EXISTS( SELECT * FROM @Temp AS T WHERE T.Info = S.LastDownLoad ) 
4

3 回答 3

2

也许这过于简单了……但是……它似乎适合……

DECLARE @Temp TABLE ( Info VARCHAR( 256 ) )

    INSERT INTO @Temp
    SELECT Distinct LastDownLoad
    FROM Securities
于 2012-05-09T16:57:38.183 回答
2

将两个答案放在一起,您将得到完整的答案:

DECLARE @Temp TABLE ( Info VARCHAR( 256 ) )

INSERT INTO @Temp
SELECT DISTINCT LastDownLoad
FROM Securities AS S
WHERE NOT EXISTS( SELECT * FROM @Temp AS T WHERE T.Info = S.LastDownLoad ) 
于 2012-05-09T17:02:09.653 回答
1

你试过用distinct吗?

DECLARE @Temp TABLE ( Info VARCHAR( 256 ) )

INSERT INTO @Temp
SELECT LastDownLoad
FROM Securities AS S
WHERE NOT EXISTS( SELECT DISTINCT * FROM @Temp AS T WHERE T.Info = S.LastDownLoad )
于 2012-05-09T16:56:57.747 回答