简体   繁体   English

如何在mysql中获取最大值的对应数据

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

I have a query A that results in : 我有一个查询A导致:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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