Mysql 选择重复行之一
我正在尝试根据 mysql 表中的 Ticket_id 选择重复条目中的最新条目,我当前的情况是这样的。
SELECT * ,
COUNT(*) AS cnt ,
ticket_id
FROM temp_tickets
GROUP BY ticket_id
ORDER BY id DESC
它给出了一行被重复的次数,但我能够选择这些多行中的最新一个
假设我有 3 个 Ticket_id,它们被重复了 5 次,所以现在我想从所有这 3 个 id 中选择最新出现的一次。
让我知道我是否需要更具体。
谢谢
I am trying to select the latest entry of the duplicate entries against the ticket_id in a mysql table , My current is something like this.
SELECT * ,
COUNT(*) AS cnt ,
ticket_id
FROM temp_tickets
GROUP BY ticket_id
ORDER BY id DESC
It gives the number of times a row is duplicated but i am able to select the latest one of those mulptiple rows
Let say i have 3 ticket_id's which got duplicated for 5 times so now i want to select the latest occurrence from all these 3 id's .
Lemme know if i have to be more specific.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法(假设“最新”意味着“最大的ID”)
我怀疑可能会想出一个更有效的解决方案涉及用户变量,但我会把它留给其他人......
Here's one way (assuming "latest" means "greatest id")
I suspect it might be possible to come up with a more efficient solution involving user variables but I'll leave that to someone else...