[英]mysql group by order by issue
我的问题是:
我有这样的日期库:
| from | to | time | text | read |
| hans | poul | 0916 | hi there | 1 |
| john | poul | 1033 | waz up | 1 |
| hans | john | 1145 | new text | 0 |
| poul | john | 1219 | message | 0 |
| poul | hans | 1233 | respond | 0 |
我想要一个输出,其中每个“从”或“到”都有按顺序列出,分组和排序的“汉斯”,如下所示:
poul - 1233 - respond - 0
john - 1145 - new text - 0
您的SQL查询可能是:-
select * from `table_name` where (`from` ='hans' or `to` ='hans') group by `from`, `to` order by time desc
如果发现任何困难,请发回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.