为不同的条目选择最新的条目

编程入门 行业动态 更新时间:2024-10-24 12:33:30
本文介绍了为不同的条目选择最新的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

关于我将如何做到这一点,我脑子里放了个屁.我只需要选择一组相同 ID 条目中的最新条目

Im having a brain fart as to how I would do this. I need to select only the latest entry in a group of same id entries

我在约会表中有记录.

lead_id app_id 4 42 3 43 1 44 2 45 2 46 (want this one) 1 48 3 49 (this one) 4 50 (this one) 1 51 (this one)

我需要的结果是 app_id 46,49,50,51

The results I require are app_id 46,49,50,51

仅约会表中的最新条目,基于重复的 Lead_id 标识符.

Only the latest entries in the appointment table, based on duplicate lead_id identifiers.

推荐答案

我认为这是更优化和更有效的方法(排序下一个分组):

I think this is much more optimal and efficient way of doing it (sorting next grouping):

SELECT * FROM ( SELECT * FROM appointment ORDER BY lead_id, app_id DESC ) AS ord GROUP BY lead_id

当您还需要表中的所有其他字段而无需复杂查询时,这将非常有用

this will be useful when you need all other fields too from the table without complicated queries

结果:

lead_id app_id 1 51 2 46 3 49 4 50

更多推荐

为不同的条目选择最新的条目

本文发布于:2023-10-14 21:52:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   最新

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!