当前位置: 代码迷 >> Oracle管理 >> 分组排序的有关问题,求答案,多谢各位大侠了
  详细解决方案

分组排序的有关问题,求答案,多谢各位大侠了

热度:53   发布时间:2016-04-24 04:42:17.0
分组排序的问题,求答案,在线等,谢谢各位大侠了
select tt.id,tt.userid,tt.begindate,tt.enddate,tt.places,tt.reason,tt.abroad,tt.info1,tt.info2,tt.info3,tt.info4,tt.info5,tt.dept from (select id,userid,begindate,enddate,places,reason,abroad,info1,info2,info3,info4,info5,dept from yjb_evection order by begindate asc) as tt group by tt.userid

这是我的sql语句,先按照userid分组,然后在每个分组中安装begindate排序,老是报错提示说命令未正确结束

------解决方案--------------------
楼主完全没有搞明白 分组的意思,,
在你的sql里面出现了group by 却没有出现相应的分组函数,比如max,min等。。。。
------解决方案--------------------
一 as 只能给字段起别名,不能给表起别名,这就是命令未正确结束的原因
二 sql语句里面没有聚合函数,为什么要用到group by 呢?
三 我认为“order by userid,begindate” 就可以满足你的需求了
  相关解决方案