insert table cdata_safe_income_new_day_analysis_item_status with t1 as ( select if(a.app_id is null,b.app_id,a.app_id) as app_id, if(a.product is null,b.product,a.product) as product, if(a.item_code_name is null,b.item_code_name,a.item_code_name) as item_code_name, case when a.app_id is null and (if(a.tiaozhang_cnt is null,0,a.tiaozhang_cnt) + if(b.tiaozhang_cnt is null,0,b.tiaozhang_cnt)) > 0 then '调账影响' when b.app_id is null and (if(a.tiaozhang_cnt is null,0,a.tiaozhang_cnt) + if(b.tiaozhang_cnt is null,0,b.tiaozhang_cnt)) > 0 then '调账影响' when a.app_id is null and (if(a.tuifei_cnt is null,0,a.tuifei_cnt) + if(b.tuifei_cnt is null,0,b.tuifei_cnt)) > 0 then '退费影响' when b.app_id is null and (if(a.tuifei_cnt is null,0,a.tuifei_cnt) + if(b.tuifei_cnt is null,0,b.tuifei_cnt)) > 0 then '退费影响' when a.app_id is null and c.voucher_begin > 0 then '优惠券影响' --- 原:续费使用了代金券 when a.app_id is null and c.voucher_end > 0 and change_order_cnt = 0 then '优惠券影响' --- 原:续费使用了代金券 when b.app_id is null and c.voucher_begin > 0 then '优惠券影响' --- 原:续费由代金券转为正常 when b.app_id is null and c.voucher_end > 0 and change_order_cnt = 0 then '优惠券影响' --- 原:续费由代金券转为正常 else 'item维度正常' end flag_status from (select app_id, product,item_code_name,sum(if(paymode_type = '调账',1,0)) as tiaozhang_cnt, sum(if(instr(paymode,'退费')>0,1,0)) as tuifei_cnt from cdata_safe_income_new_day where ftime = '${YYYYMMDD}' and paymode != '0元订单' and prod_class1_name = '基础安全' and prod_class2_name = '云原生安全' and product is not null and pay_type = '公有云' group by app_id,product,item_code_name ) a full join
时间: 2024-04-09 13:34:10 浏览: 162
cdata_safe_income_new_day_analysis_item_status 表中插入数据的SQL语句是:
```sql
insert table cdata_safe_income_new_day_analysis_item_status
with t1 as (
select if(a.app_id is null,b.app_id,a.app_id) as app_id,
if(a.product is null,b.product,a.product) as product,
if(a.item_code_name is null,b.item_code_name,a.item_code_name) as item_code_name,
case
when a.app_id is null and (if(a.tiaozhang_cnt is null,0,a.tiaozhang_cnt) + if(b.tiaozhang_cnt is null,0,b.tiaozhang_cnt)) > 0 then '调账影响'
when b.app_id is null and (if(a.tiaozhang_cnt is null,0,a.tiaozhang_cnt) + if(b.tiaozhang_cnt is null,0,b.tiaozhang_cnt)) > 0 then '调账影响'
when a.app_id is null and (if(a.tuifei_cnt is null,0,a.tuifei_cnt) + if(b.tuifei_cnt is null,0,b.tuifei_cnt)) > 0 then '退费影响'
when b.app_id is null and (if(a.tuifei_cnt is null,0,a.tuifei_cnt) + if(b.tuifei_cnt is null,0,b.tuifei_cnt)) > 0 then '退费影响'
when a.app_id is null and c.voucher_begin > 0 then '优惠券影响'
when a.app_id is null and c.voucher_end > 0 and change_order_cnt = 0 then '优惠券影响'
when b.app_id is null and c.voucher_begin > 0 then '优惠券影响'
when b.app_id is null and c.voucher_end > 0 and change_order_cnt = 0 then '优惠券影响'
else 'item维度正常'
end flag_status
from (
select app_id,
product,
item_code_name,
sum(if(paymode_type = '调账',1,0)) as tiaozhang_cnt,
sum(if(instr(paymode,'退费')>0,1,0)) as tuifei_cnt
from cdata_safe_income_new_day
where ftime = '${YYYYMMDD}'
and paymode != '0元订单'
and prod_class1_name = '基础安全'
and prod_class2_name = '云原生安全'
and product is not null
and pay_type = '公有云'
group by app_id,product,item_code_name
) a
full join <表名> b on <条件>
)
select * from t1;
```
其中 `<表名>` 和 `<条件>` 表示需要进行全连接的另外一个表的表名和连接条件。请在实际使用时将其替换为正确的表名和条件。
阅读全文