求時間段的第一筆數據跟最後一筆數據

解决方案 »

  1.   

    select * from (select top 1 * from tb order by time asc) t
    union all
    select * from (select top 1 * from tb order by time desc) t
      

  2.   

    select * from (select top 1 * from tb where time between @bt and @et order by time asc) t
    union all
    select * from (select top 1 * from tb where time between @bt and @et order by time desc) t
      

  3.   


    select top 1 * from ta where 时间 between 时间1 and 时间2 order by 时间 desc
    union all
    select top 1 * from ta where 时间 between 时间1 and 时间2 order by 时间 asc
      

  4.   

    select* from tb where 日期=max(日期)
    select* from tb where 日期=max(日期)
      

  5.   

    select * from tb where 日期=max(日期)
    union all
    select * from tb where 日期=min(日期)
      

  6.   

    SELECT * FROM TB T1
    WHERE NOT EXISTS(SELECT 1 FROM TB T2 WHERE T2.DATE<T1.DATE)
    OR NOT EXISTS(SELECT 1 FROM TB T2 WHERE T2.DATE>T1.DATE)