---------------------------| from | to | text | time |---------------------------| seg | me | ye! | 4 |---------------------------| seg | me | ye! | 3 |---------------------------| seg | yu | ye! | 2 |---------------------------| seg | yu | ye! | 1 |---------------------------大概是这个样子的一个表,我想知道能不能用一条语句提取出from=seg下所有不同的to字段值的time最新的一条数据,如果不能一句话的话写成几句也成0_0,比如上面应该获取到---------------------------| from | to | text | time |---------------------------| seg | me | ye! | 4 |---------------------------| seg | yu | ye! | 2 |---------------------------这两条数据。
2 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
使用group by 汇总即可
select t.* from t , ( select c_from,c_to,max(c_time ) as c_time from t where c_from = 'seg' group by c_from,c_to ) t1where t.c_from = t1.c_from and t.c_to = t1.c_toand t.c_time = t1.c_time
明月笑刀无情
TA贡献1828条经验 获得超4个赞
SELECT a.* FROM user_post a, ( SELECT content, MAX (post_date) post_date FROM user_post WHERE user_name = 'withrock' GROUP BY content) b WHERE a.content = b.content AND a.post_date = b.post_date
这张表的结构和你的不太一样,不过描述的问题是一样的.
添加回答
举报
0/150
提交
取消