我想獲取特定年份的每個月的銷售數據,但我在爲其構建查詢時遇到問題。如何獲取每年每月的銷售數據
這裏是我試過
SELECT COUNT(`id`) AS `total_order`
FROM orders
WHERE date BETWEEN ? AND ?
GROUP BY `total_order`
這裏是我的表看起來怎麼樣
----------------------------------------
| id | item_name | amount | time |
| 21 | item_1 | 10 | 1506675630 |
| 22 | item_2 | 30 | 1506675630 |
| 23 | item_3 | 70 | 1506675630 |
| 24 | item_4 | 100 | 1506675630 |
----------------------------------------
現在,這裏是我從查詢
1 - Total Sales amount made from the beginning of the year till today.
2 - Sales made Today
3 - Sales made in Last Month
4 - Sales Made in Last 3 month
5 - Sales Made in Last 6 Month
6 - Total Number of Sales made in every month of this particular year
爲如要 - January - 20 Feb -100 March - 200如&等。
我該如何實現這個複雜的查詢?
我發現此鏈接用於在日期中轉換數字數字:https://stackoverflow.com/questions/19271007/converting-a-numeric-value-to-date-time – Alberslash
添加時間列,如@Alberslash的日期說 –
我覺得你實際上是在尋求不同的querys。您無法在同一個查詢中表示不同的時間分組。此外,感覺就像你要求我們爲你查詢,你的嘗試甚至沒有接近它的樣子,我想知道它是否合乎邏輯。 – whiteTea