当前位置:   article > 正文

mysql获取日期最新的数据,从分组的MySQL数据获取最新的日期

mysql 取最新日期的数据

I have the following data in my database:

|NO | model | date |

+---+-------+----------+

|1 | bee |2011-12-01|

|2 | bee |2011-12-05|

|3 | bee |2011-12-12|

|4 | tar |2011-12-13|

I want to get the latest date of each model group:

| model | date |

+-------+----------+

| bee |2011-12-12|

| tar |2011-12-13|

I tried:

SELECT model, date

FROM doc

WHERE date ........????? //what is the next?

GROUP BY model

解决方案

Are you looking for the max date for each model?

SELECT model, max(date) FROM doc

GROUP BY model

If you're looking for all models matching the max date of the entire table...

SELECT model, date FROM doc

WHERE date IN (SELECT max(date) FROM doc)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/952757
推荐阅读
相关标签
  

闽ICP备14008679号