我有一個表(名稱VCAR)選擇日期範圍在兩個日期之間並獲得數
id | createddatetime |
--------------------------
1 |2016-08-20 17:23:53 |
2 |2016-08-20 17:23:53 |
3 |2016-08-20 17:23:53 |
4 |2016-08-20 17:23:53 |
4 |2016-08-20 17:23:53 |
4 |2016-08-21 17:23:53 |
3 |2016-08-21 17:23:53 |
1 |2016-08-21 17:23:53 |
1 |2016-08-21 17:23:53 |
2 |2016-08-24 17:23:53 |
3 |2016-08-24 17:23:53 |
4 |2016-08-24 17:23:53 |
2 |2016-08-29 17:23:53 |
2 |2016-08-29 17:23:53 |
3 |2016-08-29 17:23:53 |
4 |2016-08-29 17:23:53 |
4 |2016-08-30 17:23:53 |
2 |2016-08-30 17:23:53 |
3 |2016-08-30 17:23:53 |
4 |2016-08-30 17:23:53 |
我試圖得到的id的數量在特定日期範圍使用
SELECT
count(CAST(createddatetime AS DATE)),
CAST(createddatetime AS DATE),
DAYNAME(CAST(createddatetime AS DATE))
FROM vcar
WHERE
CAST(createddatetime AS DATE)>=date('2016-08-20') AND
CAST(createddatetime AS DATE)<=date('2016-08-35')
GROUP BY CAST(createddatetime AS DATE);
這給了我o/p,但我也需要顯示在某一天有零點命中的日期。如何做到這一點?
O/P我越來越
-------------------------------------- ------------------------------- ----------------------------------------
count(CAST(createddatetime AS DATE)) | CAST(createddatetime AS DATE) | DAYNAME(CAST(createddatetime AS DATE)) |
-------------------------------------- ------------------------------- ----------------------------------------
9 | 2016-08-20 | Saturday |
36 | 2016-08-23 | Tuesday |
4 | 2016-08-24 | Wednesday |
-------------------------------------- ------------------------------- ----------------------------------------
我需要什麼
-------------------------------------- ------------------------------- ----------------------------------------
count(CAST(createddatetime AS DATE)) | CAST(createddatetime AS DATE) | DAYNAME(CAST(createddatetime AS DATE)) |
-------------------------------------- ------------------------------- ----------------------------------------
9 | 2016-08-20 | Saturday |
0 | 2016-08-21 | Sunday |
0 | 2016-08-22 | Monday |
36 | 2016-08-23 | Tuesday |
4 | 2016-08-24 | Wednesday |
9 | 2016-08-25 | Thursday |
0 | 2016-08-26 | Friday |
-------------------------------------- ------------------------------- ----------------------------------------
請添加您的預期輸出。 – 1000111
@ 1000111 Ill add –
假設這些日子沒有出現在您的表格中,您可能需要使用日曆表來獲得零點擊天數。 –