我想减去2个日期,以比较当前年份与上一年度的数据,但我的查询无效。
如果我删除了一段时间,但不确定如何拉2个句号。
由于
SELECT year(date) as year, WEEK(ADDDATE(date, 5-DAYOFWEEK(date)), 3) AS 'Week', DATE,
FROM TABLE
WHERE year(date) in (2015, 2016)
AND (DATE BETWEEN "2016-10-23" AND "2016-11-12")
AND (DATE BETWEEN "2015-11-06" AND "2015-11-12")
ORDER BY DATE, year(date)
答案 0 :(得分:0)
请试试这个。
SELECT year(date) as year, WEEK(ADDDATE(date, 5-DAYOFWEEK(date)), 3) AS 'Week', DATE,
FROM TABLE
WHERE
((DATE BETWEEN "2016-10-23" AND "2016-11-12")) OR
((DATE BETWEEN "2015-11-06" AND "2015-11-12"))
ORDER BY DATE, year(date)
答案 1 :(得分:0)
我想你想要or
:
SELECT year(date) as year, WEEK(ADDDATE(date, 5-DAYOFWEEK(date)), 3) AS Week, DATE
FROM TABLE
WHERE DATE BETWEEN '2016-10-23' AND '2016-11-12' OR
DATE BETWEEN '2015-11-06' AND '2015-11-12';
注意:
date()
子句中的where
比较。答案 2 :(得分:0)
SELECT year(DATE) AS year
,WEEK(ADDDATE(DATE, 5 - DAYOFWEEK(DATE)), 3) AS 'Week'
,DATE
FROM TABLE
WHERE (
(
DATE BETWEEN '2016-10-23'
AND '2016-11-12'
)
OR (
DATE BETWEEN '2015-11-06'
AND '2015-11-12'
)
)