gpt4 book ai didi

MySQL:选择多行但限制为 1

转载 作者:太空宇宙 更新时间:2023-11-03 11:11:51 25 4
gpt4 key购买 nike

我有一个包含以下内容的表格:

food  || last_order_date 
-------------------------
pizza || 2011-10-25 19:00
=========================
pasta || 2011-10-25 23:00
=========================
pizza || 2011-10-29 15:00
=========================
pasta || 2011-10-31 18:00
=========================

我想要实现的是为每种食物获取一个按last_order_date 排序的表格。因此,结果将是:

food  || last_order_date 
-------------------------
pasta || 2011-10-31 18:00
=========================
pizza || 2011-10-29 15:00
=========================

我怎样才能做到这一点?我尝试了很多东西,但我得到的只是整张 table 的订单,而不是每个食物元素。谢谢!

最佳答案

像这样(未测试):

SELECT   food, 
MAX(last_order_date) AS max_last_order_date
FROM table
GROUP BY food
ORDER BY max_last_order_date DESC

关于MySQL:选择多行但限制为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8010543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com