quickBI:综合查询一例

背景:通过电话或者兑换码查询对应的课程权限,在quickbi中代码如下:

select 
b.course_id 课程id,
b.class_name 课程名称,
a.user_id 用户id,
u.user_full_name 姓名,
sum(a.listen_status) 听课总数,
sum(a.work_status) 作业总数,
(case when a.course_type in(2,101,102,103) then 66 when a.course_type in (1000,1001) then 72 when a.course_type=200 then 44  when a.course_type=300 then 35 else 0 end) 总课数,
concat(round(sum(a.listen_status)*100/(case when a.course_type in(2,101,102,103) then 66 when a.course_type in (1000,1001) then 72 when a.course_type=200 then 44  when a.course_type=300 then 35 else 0 end),2),'%') 听课率 ,
c.card_password 兑换码,
(case c.card_is_unlock when 0 then '已兑换' when 1 then '未兑换' when 2 then '已退款' else c.card_is_unlock end ) 激活状态,
c.card_price 价格
from app_user.class_hwork_info a 
  join app_user.class_info b on a.course_type=b.course_type
  join app_user.user_info u on a.user_id=u.id
	left join app_goods.card_info c on a.user_id=c.card_unlock_user_id
where 1=1
and b.course_id=${course_id}
and concat(u.phone,c.card_password) like '%${phone}%'

说明:本来可以通过子查询完成,但是由于quckbi会改写sql从而导致语法出错,不得已改为为concat函数来实现用电话或者兑换码查询的功能。

 

效果图:

 

posted @ 2022-01-21 15:59  xiaoyongdata  阅读(148)  评论(0)    收藏  举报