我有两张桌子......
我试图返回这样的查询...
+----------------------------------+--------------------+
| DATEDIFF(shippedDate, orderDate) | COUNT(shippedDate) |
+----------------------------------+--------------------+
| 1 | 50 |
| 2 | 49 |
| 3 | 52 |
| 4 | 52 |
| 5 | 59 |
| 6 | 45 |
| 7 | 2 |
| 8 | 2 |
| 65 | 1 |
+----------------------------------+--------------------+
但是我没有得到它。我知道我必须做一个分组并使用DateDiff()和Count()......
我试过这个但是不对 mysql:
select DATEDIFF(shippedDate,orderDate), COUNT(shippedDate) from Orders Group by shippedDate;
有什么建议吗?
答案 0 :(得分:1)
您需要group by
datediff()
:
select DATEDIFF(shippedDate, orderDate), COUNT(shippedDate)
from Orders
Group by DATEDIFF(shippedDate, orderDate);
答案 1 :(得分:1)
您需要在group by语句中添加datediff(shippedDate,orderDate)而不是shippingDate