gpt4 book ai didi

php - 获取mysql中最近记录的组的所有id

转载 作者:行者123 更新时间:2023-11-29 10:57:18 24 4
gpt4 key购买 nike

我的 MySQL 数据库中有具有不同组代码的用户。我正在根据他们当前的位置将他们的纬度和经度保存在数据库中。

Problem is I am not able to get their recent records according to their group code.

我已经尝试过了

     SELECT * FROM tracklatlong WHERE id IN (SELECT MAX( id ) FROM 
tracklatlong GROUP BY 'track_CfiUw');

但我只获取此 track_CfiUw 组代码的最后记录。

我想要如下的结果

enter image description here

I want result like recent records of perticular user according their group

最佳答案

您的查询应该是这样的,

 SELECT tl1.id,tl1.admin_id,tl1.name,tl1.groupcode
FROM tracklatlong tl1
LEFT JOIN tracklatlong tl2 ON (tl1.name = tl2.name AND tl1.id < tl2.id)
WHERE tl2.id IS NULL AND tl1.groupcode = 'track_CfiUw';

但是您将按 group_code 值对其进行分组。

关于php - 获取mysql中最近记录的组的所有id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42834273/

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