基于一列,查询每隔一天获取记录的查询语句

3

我有一张名为altstore的表,其中有一个列checkindate用于保存日期。我的需求是从一个月中获取交替日期的记录,例如,如果是这个月的第一天,则获取第3天等等。请帮我写出可用的SQL查询语句。 谢谢。


你用的是哪个数据库服务器呢? - Eric
3个回答

2

尝试使用以下方法:

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

这里的 startingdate 是本月的第一天,而 enddatecheckindate 列中的值。


2

使用 datepartmodulo

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

为什么要检查日期限制(并且限制到2011年)? - aF.
@aF. - 问题的措辞让我觉得用户只想要一个月的交替天数。 - Eric

0

尝试使用类似以下的内容:

SELECT * from yourtable where date(checkindate)%2 !=0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接