qq994134665
xiao224269
采纳率0%
2017-12-09 09:29 阅读 1.7k

关于oracle数据库order by后排序的问题

5

```select recommend_user_id,count(recommend_user_id) count,MAX(time) time
from(
select i.user_id,u.recommend_user_id,i.time
from users u
right join (select b.user_id, b.time
from (select u.id, u.time
from users u
where time >= to_date('2017/12/01', 'yyyy/mm/dd')
and time < to_date('2018/01/19', 'yyyy/mm/dd')
and u.recommend_user_id <> 0) a
inner join (select user_id, MAX(time) time
from invests
where time >= to_date('2017/12/01', 'yyyy/mm/dd')
and time < to_date('2018/01/19', 'yyyy/mm/dd')
group by user_id
order by time) b
on a.id = b.user_id) i
on u.id = i.user_id
) group by recommend_user_id order by count desc,time


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • qq994134665 xiao224269 2017-12-09 09:30
    
    

    select i.user_id,u.recommend_user_id,i.time
    from users u
    right join (select b.user_id, b.time
    from (select u.id, u.time
    from users u
    where time >= to_date('2017/12/01', 'yyyy/mm/dd')
    and time < to_date('2018/01/19', 'yyyy/mm/dd')
    and u.recommend_user_id <> 0) a
    inner join (select user_id, MAX(time) time
    from invests
    where time >= to_date('2017/12/01', 'yyyy/mm/dd')
    and time < to_date('2018/01/19', 'yyyy/mm/dd')
    group by user_id
    order by time) b
    on a.id = b.user_id) i
    on u.id = i.user_id
    这一段取到时间的,到最后一层时间就为空了,为什么?

    点赞 评论 复制链接分享
  • lxy923 lxy923 2017-12-09 17:00

    从内层逐个运行下,也许就有答案了

    点赞 评论 复制链接分享
  • duan3702 木子3702 2017-12-10 14:30

    语句分步执行,一段代码一段执行,大部分原因关联条件导致的

    点赞 评论 复制链接分享
  • a_jinjun a_jinjun 2018-02-07 06:53

    别名别用关键字, order by count desc, time 换成order by count(recommend_user_id) 试试

    点赞 评论 复制链接分享

相关推荐