这是我的sql:
select * from table as t
where DateAndTime BETWEEN '2011-03-01' AND '2012-01-25'
问题: *例如,我需要从2012年1月开始每天获取数据(周末除外)。
我该怎么做?
答案 0 :(得分:0)
试试这个。
SELECT *
from table as t
where (DateAndTime BETWEEN '2011-03-01' AND '2012-01-25') AND
DateAndTime NOT IN ('2011-03-03', '2011-03-10') -- Put the excempted
-- dates here
答案 1 :(得分:0)
select * from table as t
where DateAndTime BETWEEN '2011-03-01' AND '2012-01-25'
AND (DATEPART(weekday, DateAndTime ) <> 1 and DATEPART(weekday,DateAndTime ) <> 6)
(DATEPART(weekday, DateAndTime ) = 1
是星期天
(DATEPART(weekday, DateAndTime ) = 6
是星期六
答案 2 :(得分:0)
SELECT
*
FROM
yourtable AS T
WHERE
yourdatetimefield BETWEEN STR_TO_DATE('2012-01-01', '%Y-%m-%d') AND
STR_TO_DATE('2012-12-31', '%Y-%m-%d')
AND
DAYOFWEEK(yourdatetimefield) <> 1 AND ' Sunday
DAYOFWEEK(yourdatetimefield) <> 7 ' Saturday
GROUP BY
DAY(yourdatetimefield);
答案 3 :(得分:0)
尝试此查询
SELECT * FROM tableName
WHERE DateAndTime BETWEEN '2011-03-01' AND '2012-01-25'
AND WEEKDAY(DateAndTime) <= 4