我有date_ini和date_expired表的政策,並希望表示本date_ini和日期在2015年如何根據年份顯示日期?
這裏過期策略是信息:
|date_ini| |date_end|
2015-01-01 2015-06-03 Here is in the period 2015
2014-02-03 2015-09-08 Here is in the period 2015
2015-06-03 2016-09-08 Here is in the period 2015
2016-01-03 2016-09-08 Here is not in the period 2015
2015-06-03 2017-09-08 Here is in the period 2015
我想這demo:
select * from policies where YEAR(date_ini) >= 2015 AND YEAR(date_end) <= 2015
我應該有這樣的答案:
|date_ini| |date_end|
2015-01-01 2015-06-03
2014-02-03 2015-09-08
2015-06-03 2016-09-08
2015-06-03 2017-09-08
請有人可以幫助我這個查詢?
我不知道你爲什麼期待這個結果。您正在過濾** ** date_ini爲2015或更高版本和date_end爲2015或更低版本的行。換句話說,這兩個字段在2015年必須有一個日期。唯一符合這些條件的行是第一個。 – Oldskool 2015-02-24 16:48:43