我有这样的桌子。
thread_id, message_id, tomsg, frommsg, msg, time, readstatus
1,1,[email protected],[email protected],Hi,"2013-12-04 18:06:58",0
2,1,[email protected],[email protected],Hello,"2013-12-06 11:11:11",0
3,1,[email protected],[email protected],"How R U ?","2013-12-18 11:55:15",0
4,2,[email protected],[email protected],sem1,"2013-12-04 18:06:58",1
5,2,[email protected],[email protected],sem2,"2013-12-06 11:11:11",0
此处, Comma
分隔列数据。我的信誉不足,因此无法上传图片。
现在假设我希望dat的每个消息只有最后一个线程,那我该怎么办?即从message_id 1应该返回最后一个完整线程3行。有什么建议吗?
尝试这个:
SELECT t.thread_id, t.message_id, t.tomsg, t.frommsg, t.msg, t.time, t.readstatus
FROM (SELECT t.thread_id, t.message_id, t.tomsg, t.frommsg, t.msg, t.time, t.readstatus
FROM thread t ORDER BY t.message_id, t.thread_id DESC
) AS t
GROUP BY t.message_id
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句