id no value time
1 1 1 2016-02-26 10:10:10
2 2 5 2016-02-26 10:11:10
3 1 10 2016-02-26 10:12:10
4 1 11 2016-02-26 10:13:10
5 2 8 2016-02-26 10:14:10
6 1 7 2016-02-26 10:17:10
7 1 3 2016-02-26 10:18:10
8 3 5 2016-02-26 10:19:10
9 3 1 2016-02-26 10:20:10
结果:
id no value time
7 1 3 2016-02-26 10:18:10
5 2 8 2016-02-26 10:14:10
9 3 1 2016-02-26 10:20:10
先按照no分组,然后找到每一个组里面time最近的列,结果是以no升序拍
1 1 1 2016-02-26 10:10:10
2 2 5 2016-02-26 10:11:10
3 1 10 2016-02-26 10:12:10
4 1 11 2016-02-26 10:13:10
5 2 8 2016-02-26 10:14:10
6 1 7 2016-02-26 10:17:10
7 1 3 2016-02-26 10:18:10
8 3 5 2016-02-26 10:19:10
9 3 1 2016-02-26 10:20:10
结果:
id no value time
7 1 3 2016-02-26 10:18:10
5 2 8 2016-02-26 10:14:10
9 3 1 2016-02-26 10:20:10
先按照no分组,然后找到每一个组里面time最近的列,结果是以no升序拍
解决方案:100分
这么写:
select id,no,value,time from ( select * from t3 order by no,time desc ) t group by no;