复杂SQL案例:用户退款信息查询
供参考:
select t3.course_id 课程id, t3.user_id 用户ID, u.user_full_name 姓名, -- u.phone, concat(u.company,' ',ex.user_enterprise) 公司或企业, t3.right_1 权限状态, t3.right_0 退款数, t3.exit_date 退款日期 from ( select course_id, user_id, sum(right_1) right_1, sum(right_0) right_0, group_concat(exit_date) exit_date from ( select course_id,user_id, (case current_status when 1 then 1 else 0 end ) right_1, (case current_status when 0 then 1 else 0 end ) right_0, (case current_status when 0 then update_date else null end ) exit_date from ( select distinct course_id,user_id,date(create_time) create_date,current_status, date_format(update_time,'%Y-%m-%d %H:%i') update_date from app_goods.user_rights_course where course_id=${corse_id} ) t1 ) t2 where 1=1 group by course_id,user_id having sum(right_0)>=2 ) t3 left join app_user.user_info u on t3.user_id=u.id left join app_user.user_extend_info ex on t3.user_id=ex.user_id order by t3.course_id,t3.right_0 desc
本文来自博客园,作者:xiaoyongdata(微信号:xiaoyongdata),转载请注明原文链接:https://www.cnblogs.com/xiaoyongdata/p/15467596.html