2013-05-18 64 views
0

一個最大值對應的數據我有導致查詢:如何獲得在MySQL

orders | date_added 

10  |  2013-01-09   
24  |  2013-01-10   
13  |  2013-01-11   

我想拿到訂單的相應日期的最大數量.. 這裏的我的查詢到目前爲止

SELECT MAX(orders) 
FROM (
     SELECT COUNT(order_id) AS orders, DATE(date_added) FROM `order` 
     WHERE YEAR(date_added) = YEAR(NOW()) 
     GROUP BY DATE(date_added) 
     ) AS daily_orders" 

回答

1

我認爲這將解決這個

SELECT COUNT(order_id) AS orders, DATE(date_added) FROM `order` 
     WHERE YEAR(date_added) = YEAR(NOW()) 
     GROUP BY DATE(date_added) 
ORDER BY orders DESC LIMIT 1 
+0

我放聲大笑!我不知道我錯過了這個 –