复杂SQL案例:用户听课情况查询
供参考:
select h.course_id, h.course_type, i.course_title, r.id res_id, r.res_title, h.user_id, u.user_full_name user_name,u.phone, round(d.living_duration/60,1) living_duration,round(d.record_duration/60,1) record_duration, h.done_time, (case when h.listen_status='1' then '已打卡' else '' end) listen_status, d.create_time,d.update_time from ( -- 作业:用course_type关联course_id select h.user_id,h.listen_status,h.score,h.done_time,c.course_id,c.course_type from app_user.class_hwork_info h left join app_user.class_info c on h.course_type=c.course_type -- where h.user_id in(xxx) and h.course_type=xxx ) h left join ( -- 作业:用日期关联res_id select cx.course_id,cx.res_date done_time,res.res_id res_id from app_user.cxkt_res_date cx left join app_goods.course_info_res res on cx.course_info_res_id=res.id where cx.course_info_res_id>0 ) c on h.course_id=c.course_id and h.done_time=c.done_time left join ( select user_id,course_id,res_id,concat(res_id,'-',rel_id) all_res_id,living_duration,record_duration,create_time,update_time from bi_data.user_study_rel_duration_ ) d on h.course_id=d.course_id and h.user_id=d.user_id and c.res_id=d.res_id left join app_goods.course_info i on h.course_id=i.id left join app_goods.course_res r on c.res_id=r.id left join app_user.user_info u on h.user_id=u.id
本文来自博客园,作者:xiaoyongdata(微信号:xiaoyongdata),转载请注明原文链接:https://www.cnblogs.com/xiaoyongdata/p/15467435.html