請看看我的books
表:如何獲取兩個日期之間的所有日期?
books
+-----+----------+------------+------------+
| id | venue_id | from_date | to_date |
+-----+----------+------------+------------+
| 1 | 8 | 2015-07-21 | 2015-07-28 |
| 2 | 5 | 2015-08-03 | 2015-08-25 |
+-----+----------+------------+------------+
我要查看from_date
和to_date
之間的所有日期安排venue_id
= 8
我的輸出應該是:
Array
(
[0] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-21
)
[1] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-22
)
[2] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-23
)
[3] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-24
)
[4] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-25
)
[5] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-26
)
[6] => Array
(
[id] => 1
[venue_id] => 8
[today] => 2015-07-27
)
)
today
計算從from_date
日期到to_date
日期。但是我的想法對於那個查詢是空白的。如何編寫一個MySQL查詢來獲得像上面顯示的輸出結果?
您的輸出省略了結束日期 - 是否正確?因此,如果開始日期和結束日期相同,則不應顯示數據。或者你確定結束日期總是晚於開始日期?你打算創建一個列表日期列表嗎?然後它變得容易。否則,這並不容易。 –