我有兩個表...SQL GROUP BY和骨料需要幫助
- 訂單(訂單編號,orderDate存儲,發貨日期,requiredDate,狀態customerNumber之)和
- 訂單明細(訂單編號,產品代碼,quantityOrdered,priceEach ,orderLineNumber)
我試圖返回這樣的查詢...
+----------------------------------+--------------------+
| DATEDIFF(shippedDate, orderDate) | COUNT(shippedDate) |
+----------------------------------+--------------------+
| 1 | 50 |
| 2 | 49 |
| 3 | 52 |
| 4 | 52 |
| 5 | 59 |
| 6 | 45 |
| 7 | 2 |
| 8 | 2 |
| 65 | 1 |
+----------------------------------+--------------------+
但我只是沒有得到它。我知道我必須做1組,並使用則DateDiff()和COUNT()...
我已經試過這一點,但它不是正確的 的mysql:
select DATEDIFF(shippedDate,orderDate), COUNT(shippedDate) from Orders Group by shippedDate;
有什麼建議?
刪除了SQL Server的標記,因爲問題明確地說: 「MySQL的」 組添加DATEDIFF(發貨日期,orderDate存儲) 。 –