hiveレポート統計関連文の整理

4243 ワード

詳細
1.case when thenデータ辞書変換
2.ROUND(CEILING(t 1.order_amount*1)/100,2)上取整+保留位小数
3.substring(cast(t.trade_time as string)、0,7)日付変換、月へ、10であれば日へ
4.unix_timestamp(create_time)+3005.order by条件とクエリー結果が競合する場合は、order by条件を先に削除したほうがいいです.
select date1  ,XXXid1  ,paymethod1  , count1  ,orderamount1  ,
CASE
when paymethod1='PayPal' then fee1*5 
else  fee1 
END as fee2  from 
(select a.tradetime as date1,a.XXXId as  XXXid1 ,a.paymethod as paymethod1,count(*) as  count1,sum(a.orderamount)  as orderamount1,sum(a.fee) as fee1 from 
(select   t1.pay_seq  as payseq, substring(cast(t.trade_time as string),0,10) as tradetime,t.pay_amount as payamount ,t.order_amount  as orderamount 
,CASE 
when t.XXX_id='YYY160823142921802' and t1.order_amount*6 >= 10 then ROUND(CEILING(t1.order_amount*0.6)/100,2)
when t.XXX_id='YYY160823142921802' and t1.order_amount*6 < 10 then 0.01
when t.XXX_id='YYY160809193618262' and t1.order_amount*10 >= 10 then ROUND(CEILING(t1.order_amount*1)/100,2)
when t.XXX_id='YYY160809193618262' and t1.order_amount*10 < 10 then 0.01
when t.XXX_id='YYY160712075256902' and t1.order_amount*10 >= 10 then ROUND(CEILING(t1.order_amount*1)/100,2)
when t.XXX_id='YYY160712075256902' and t1.order_amount*10 < 10 then 0.01
when t.XXX_id='YYY171009125604524' and t1.order_amount*10 >= 10 then ROUND(CEILING(t1.order_amount*1)/100,2)
when t.XXX_id='YYY171009125604524' and t1.order_amount*10 < 10 then 0.01
when t.XXX_id='YYY171121150246521' and t1.order_amount*10 >= 10 then ROUND(CEILING(t1.order_amount*1)/100,2)
when t.XXX_id='YYY171121150246521' and t1.order_amount*10 < 10 then 0.01
end as fee ,
case
when t.XXX_id='YYY160823142921802' THEN ' A' 
when t.XXX_id='YYY170320123235979' THEN ' B' 
END as XXXId,
case  
when t2.pay_method='A0' THEN ' ' 
WHEN t2.pay_method='A1' THEN ' ' 
WHEN t2.pay_method='A2' THEN ' ' 
END  as paymethod 
 from odl_table_name_finance t,odl_table_name_payment_finance t1,odl_table_name_payment_detail_finance t2 where t.fund_order_id = t1.fund_order_id and t1.pay_seq = t2.pay_seq and 
 substring(cast(t.trade_time as string),0,7) ='2017-12' and t.order_type='03' and t.order_status='S' and t1.pay_status='S' and t.order_status='S'    ) 
 a where 1=1 group by a.XXXId,a.tradetime,a.paymethod order by a.tradetime,a.XXXId,a.paymethod limit 1000) dd 
 where 1=1 limit 1000
 
 
select a.alldate ,a.allamount as  allamount,a.allcount as allcount,b.sucamount as sucamount,b.succount as succount,c.amount5 as amount5,c.count5 as count5  
from
(select sum(order_amount) allamount,count(*) allcount,partner_id as partnerid1,substring(cast(create_time as string),0,10) alldate from odl_table_name_finance where create_time between '2017-12-01' and '2018-01-01' and order_type='03' group by partner_id,substring(cast(create_time as string),0,10)) a 
left join 
(select sum(order_amount) sucamount,count(*) succount,partner_id as partnerid2,substring(cast(create_time as string),0,10) sucdate from odl_table_name_finance where create_time between '2017-12-01' and '2018-01-01' and order_type='03' and order_status='S' group by partner_id,substring(cast(create_time as string),0,10)) b
on a.partnerid1=b.partnerid2 
and a.alldate = b.sucdate
left join 
(select sum(order_amount) amount5,count(*) count5,partner_id  as partnerid3,substring(cast(create_time as string),0,10) sucdate from odl_table_name_finance where create_time between '2017-12-01' and '2018-01-01' and order_type='03' and order_status='S'   and   unix_timestamp(create_time)+300