本文介绍了在postgres中按对选择不同的最后一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有消息的表:
从消息
$ p $中选择(user_from,user_to)
*
p>
这就是我得到的:
我确实得到了两个用户之间的唯一对话行,但不是最后一个。
如何只选择两个用户之间的最后一个唯一对话?
已编辑:预期输出:
解决方案这是我的操作方式:
SELECT DISTINCT ON(user_from,user_to)*
FRO M条消息
ORDER BY user_from,user_to,date + time DESC
I have a table with messages:
I need to only one LAST by date and time conversation between two users and here is what i do:
select distinct on (user_from, user_to) * from messages
Here is what I get:
I do get one unique conversations lines between two users, but its not the last one.
How should I select only the last one unique conversation between two users?
EDITED: expected output:
解决方案Here is how I did it:
SELECT DISTINCT ON (user_from, user_to) * FROM messages ORDER BY user_from, user_to, date+time DESC
这篇关于在postgres中按对选择不同的最后一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!