SQL从表中获取第一个不同的值

时间:2014-12-29 13:27:04

标签: sql ms-access-2010

我想检查这个SQL是否正确。

"SELECT TOP 1 * FROM (SELECT DISTINCT [Entry Date] FROM [" + group + "]) WHERE [Entry Date]>#" + initDate + "# ORDER BY [Entry Date]"

提前谢谢

解决了:我发现sql完美无缺。我只是在程序中犯了一个小错误。现在解决了。

2 个答案:

答案 0 :(得分:0)

你想要这个吗?

select min([Entry Date])
from [group]
where [Entry Date] > #" + initDate

或者这个:

select top 1 *
from [group]
where [Entry Date] > #" + initDate
order by [Entry Date]

答案 1 :(得分:0)

这应该有用。

SELECT B.* FROM (
SELECT [EntryDate] FROM Group

EXCEPT

SELECT [EntryDate] FROM (

SELECT [EntryDate]
,ROW_NUMBER() OVER (ORDER BY [EntryDate]) AS Rown 
from Group 
                        )A WHERE Rown > 1 )B JOIN Group C ON a.[EntryDate] = B.[EntryDate]

WHERE [Entry Date] > #" + initDate
ORDER BY [Entry Date]