查询以基于列获取备用日期的记录

时间:2012-01-05 18:24:55

标签: sql date

我有一个表altstore,其中包含一个用于保存日期的列checkindate。我的要求是获取一个月的备用天数记录,例如当月的第1天,然后是第3天,依此类推。请帮我处理我可以使用的sql查询。 感谢。

3 个答案:

答案 0 :(得分:2)

尝试使用:

select * from altstore
where DATEDIFF (day,startingdate,enddate) % 2 is 1

此处startingdate是该月的第一个日期,enddatecheckindate列中的值。

答案 1 :(得分:2)

使用datepartmodulo

select
    *
from
    table
where
    datepart(dd, checkindate) % 2 = 1
    and checkindate between '2011-12-01' and '2011-12-31'

答案 2 :(得分:0)

尝试在这些方面使用一些东西:

SELECT * from yourtable where date(checkindate)%2 !=0
相关问题