gpt4 book ai didi

php - 按最大日期选择 account_id

转载 作者:可可西里 更新时间:2023-11-01 09:05:10 24 4
gpt4 key购买 nike

你好,我有如下表格设计

ID       account_id       score     date------------------------------------------    1       500             4               x2       764             4               x3       500             6               x4       500             7               x5       764             5               x

I'm trying to get all rows with the latest account_id entry

so my code should return

ID       account_id       score     date------------------------------------------    4       500             7               x5       764             5               x

I tried the following code but it seems to return the first entry but with the latest date

SELECT account_id,score, max(date) from table group by account_id

最佳答案

情况 1:如果 id 是自增列或者 max(id) 表示最新行。

select * from
(select * from table_name
order by id desc) temp
group by account_id

情况 2:如果 date 列决定最新行,则将 order 子句 中的 id 替换为 date组子句.

关于php - 按最大日期选择 account_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390192/

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