(*^_^*)静一静 2020-12-29 08:46 采纳率: 18.8%
浏览 19
已采纳

一个复杂sql的求助

 

  • 写回答

6条回答 默认 最新

  • bj_0163_bj 2020-12-29 09:28
    关注
    如果你是hive等有row_number的sql 就这么写
    select mobile,action,lendId
    from (
    select A.mobile,A.action,b.lendId,row_number() over(partition by A.mobile,A.action order by b.logtime) rw 
    from A 
    join B
    on A.mobile=B.mobile 
    where a.logtime<=b.logtime
    ) t 
    where rw=1
    
    
    
    如果你是mysql这种没有row_number的sql就这样写
    select t.mobile,t.action,B.lendId
    from (
    select A.mobile,A.action,min(b.logtime) mn 
    from A 
    join B
    on A.mobile=B.mobile 
    where a.logtime<=b.logtime
    ) t 
    join B
    on t.mn=B.logtime
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?