我有一张名为altstore的表,其中有一个列checkindate用于保存日期。我的需求是从一个月中获取交替日期的记录,例如,如果是这个月的第一天,则获取第3天等等。请帮我写出可用的SQL查询语句。 谢谢。
尝试使用以下方法:
select * from altstore
where DATEDIFF (day,startingdate,enddate) % 2 is 1
这里的 startingdate
是本月的第一天,而 enddate
是 checkindate
列中的值。
使用 datepart
和 modulo
:
select
*
from
table
where
datepart(dd, checkindate) % 2 = 1
and checkindate between '2011-12-01' and '2011-12-31'
尝试使用类似以下的内容:
SELECT * from yourtable where date(checkindate)%2 !=0