我的问题是:
我有一个这样的日期库:
| 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 |
我想要一个输出,其中每个"从"或"到"都有"hans"列出,分组并按时间排序,如下所示:
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
如果您发现任何困难,请回发。