select example_a from example where time <=2009-11-01 and time >= 2009-01-01 在这个SQL语句里能否直接得到第一行example_a数据和最后一行example_a数据呢? 我现在的解决方案是TOP 1,然后在倒序TOP 1,这样的话影响效率。加个自增列 用max(id)和min(id)呢? 只能这样吧.
解决方案是TOP 1,然后在倒序TOP 1 SQL code: select example_a from example t where [time] <='2009-11-01' and [time] >= '2009-01-01' and (not exists(select 1 from example where [time] <='2009-11-01' and [time] >= '2009-01-01' and [time]>t.[time]) or not exists(select 1 from example where [time] <='2009-11-01' and [time] >= '2009-01-01' and [time]<t.[time]) )