oracle怎么同时使用group by 和 order by

现在有个表
ID(pk) | NAME | TIME
1 张三 2011-11-13
2 张三 2011-11-12
3 李四 2011-11-13
4 李四 2011-11-12
我现在想查出 同一个人的,时间最近的一条数据
oracle的sql应该怎么写
如上面的表,查出的结果应该是
ID(pk) | NAME | TIME
1 张三 2011-11-13
3 李四 2011-11-13

如果time是date型,直接group by max取出来即可
select a.id, a.status, a.time
from A, (select status, max(time) time from A group by A.status) B
where A.status = B.status
and A.time = B.time;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-02-17
order by 总是放在sql语句的最后。你这个直接对time字段进行order by 就可以了呀。降序排列。
相似回答