php – 如何使用MySQL获取最新日期
发布时间:2020-12-13 17:09:37 所属栏目:PHP教程 来源:网络整理
导读:如何使用 MySQL获取最新日期?我试过最大但我没有得到我想要的结果.我的表看起来像这样: +---------+---------+-----------------------+--------+------------+---------+| Name | idStore | Name | idItem | date | price |+---------+---------+--------
如何使用
MySQL获取最新日期?我试过最大但我没有得到我想要的结果.我的表看起来像这样:
+---------+---------+-----------------------+--------+------------+---------+ | Name | idStore | Name | idItem | date | price | +---------+---------+-----------------------+--------+------------+---------+ | walmart | 1 | Red Delicious Apples | 1 | 2011-10-22 | 0.98000 | | walmart | 1 | Red Delicious Apples | 1 | 2011-10-28 | 0.98000 | | walmart | 1 | Red Delicious Apples | 1 | 2011-10-28 | 0.98000 | | walmart | 1 | Red Delicious Apples | 1 | 2011-11-22 | 0.98000 | | walmart | 1 | Honeycrisp Apples | 2 | 2011-10-22 | 1.98000 | | walmart | 1 | Sonya Apples | 3 | 2011-10-22 | 2.88000 | | walmart | 1 | Gold Delicious Apples | 4 | 2011-10-22 | 0.98000 | | walmart | 1 | Sweet Tango Apples | 5 | 2011-10-22 | 2.48000 | | walmart | 1 | Granny Smith Apples | 6 | 2011-10-22 | 1.28000 | | walmart | 1 | Fugi Apples | 7 | 2011-10-22 | 1.38000 | +---------+---------+-----------------------+--------+------------+---------+ 我想得到这张桌子: +---------+---------+-----------------------+--------+------------+---------+ | Name | idStore | Name | idItem | date | price | +---------+---------+-----------------------+--------+------------+---------+ | walmart | 1 | Red Delicious Apples | 1 | 2011-11-22 | 0.98000 | | walmart | 1 | Honeycrisp Apples | 2 | 2011-10-22 | 1.98000 | | walmart | 1 | Sonya Apples | 3 | 2011-10-22 | 2.88000 | | walmart | 1 | Gold Delicious Apples | 4 | 2011-10-22 | 0.98000 | | walmart | 1 | Sweet Tango Apples | 5 | 2011-10-22 | 2.48000 | | walmart | 1 | Granny Smith Apples | 6 | 2011-10-22 | 1.28000 | | walmart | 1 | Fugi Apples | 7 | 2011-10-22 | 1.38000 | +---------+---------+-----------------------+--------+------------+---------+ 我很难搞清楚这一点.谢谢! 解决方法
在线示例查询
http://data.stackexchange.com/stackoverflow/q/118881/how-can-i-get-the-most-resent-date-using-mysql SELECT NameStore,idStore,Name,idItem,max(date) AS date,price FROM tablename GROUP by NameStore,price ORDER BY date DESC,idItem ASC (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |