查询最近五个交易日的数据,周六周日不查,比如今天星期三,就查询本周一,二,三和上周四,五的数据,这个条件应该怎么写

解决方案 »

  1.   

    select top 5 * from 表 where date not exist '周六,周日'
      

  2.   

    如果你的数据顺序是按时间从大到小排的,并且每天都有的话,那楼上的SQL可行。
    如果变数比较大,可以先用C#获取要查询的日期,再根据这个日期去取数据。
      

  3.   


    where datecol>dateadd(day,-7,'2007-6-1')
    and datename(dw,datecol) not in ('星期六','星期日')
    给分吧
      

  4.   

    这个应该是只有日期 没有星期的数据吧 ??
    DATEPART(WEEKDAY,日期)  not in () 就行   忘了返回值是啥了 具体 自己查, 这样记忆深
      

  5.   


    SELECT TOP 5 * FROM Performance p 
    WHERE p.PerformanceDate<'2010-5-1' and datepart(dw,p.PerformanceDate) NOT IN (1,7)
    ORDER BY p.PerformanceDate 
      

  6.   


    --忘了排序
    SELECT TOP 5 * FROM Performance p 
    WHERE p.PerformanceDate<'2010-5-1' and datepart(dw,p.PerformanceDate) NOT IN (1,7)
    ORDER BY p.PerformanceDate desc