简体   繁体   中英

How to get the corresponding data of a max value in mysql

I have a query A that results in :

orders    |   date_added 

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

I want to get the max number of orders with the corresponding date .. Here's my query so far

 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"

I think this will solve this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM