使用yml简化多行sql语句案例
task:
sql:
# 将某个值插入到报表
- insert into report_app_detail(curr_date,key_name,key_value) values(:curr_date,:title,:curr_value)
# 删除当日报表信息
- delete from report_app_detail where curr_date='%s'
# 获取用户信息
- select '#当前日期#' curr_date,'当日新增用户数' title,count(*) curr_value from app_user.user_info where create_time>='#当前日期#' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#'curr_date,'累计用户数' title,count(*) curr_value from app_user.user_info where create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#'curr_date,'累计小组数' title,count(*) curr_value from app_user.group_info where group_status=1 and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#'curr_date,'累计小组成员数' title,count(*) curr_value from app_user.group_member where member_is_valid=1 and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day) and group_id not in (select id from app_user.group_info where group_status = '0')
# 获取解锁码信息
- select '#当前日期#' curr_date,'累计卡总数' title,count(*) curr_value from app_goods.card_info where create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计实体卡总数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计实体卡出库总数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and card_use_status='1' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'实体卡累计解锁总数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and card_use_status='1' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'实体卡当日解锁数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and card_use_status='1' and (card_unlock_time>='#当前日期#' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day))
union all
select '#当前日期#' curr_date,'累计虚拟卡总数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计虚拟卡出库总数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and card_use_status='1' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计虚拟卡解锁总数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and card_use_status='1' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'虚拟卡当日解锁数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and card_use_status='1' and (card_unlock_time>='#当前日期#' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day))
# 本日订单查询
- select
date(create_time) curr_date,
count(distinct user_id) user_c,
count(1) order_c,
sum(if(order_status=0,1,0)) dzf_c,
sum(if(order_status=1,1,0)) yzf_c,
sum(if(order_status=2,1,0)) tkz_c,
sum(if(order_status=3,1,0)) ytk_c,
sum(if(order_status=9,1,0)) ygb_c,
sum(if(order_type=0,1,0)) kc_c,
sum(if(order_type=1,1,0)) jsm_c,
sum(if(pay_type=0,1,0)) wx_c,
sum(if(pay_type=1,1,0)) zfb_c,
sum(if(pay_type=2,1,0)) apple_c,
sum(if(device_type='android',1,0)) and_c,
sum(if(device_type='ios',1,0)) ios_c,
sum(if(order_status=1,real_fee,0)) total_money
from app_goods.app_order
where create_time>='#当前日期#' and create_time<date_add('#当前日期#',INTERVAL 1 day)
# 插入到报表
- replace into report_order(日期,用户数,订单总数,待支付数,已支付数,退款中数,已退款数,已关闭数,课程数,解锁码数,微信支付数,支付宝支付数,苹果支付数,安卓数,IOS数,实收总额)
values (:curr_date,:user_c,:order_c,:dzf_c,:yzf_c,:tkz_c,:ytk_c,:ygb_c,:kc_c,:jsm_c,:wx_c,:zfb_c,:apple_c,:and_c,:ios_c,:total_money)
本文来自博客园,作者:xiaoyongdata(微信号:xiaoyongdata),转载请注明原文链接:https://www.cnblogs.com/xiaoyongdata/p/15464503.html