File size: 5,537 Bytes
4a5d0b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | sql_query_uk_fr = """
with tb_sales
as
(
select date_format(a.purchase_date,'%%Y/%%m/%%d') dt,
a.site
,case when a.sku like '%%REF' then concat(c.product_name," ",'Refurbished') else c.product_name end product_name
,case when a.sku like '%%REF' then concat(c.product,'REF') else c.product end product
,case when a.sku like '%%REF' then concat(c.sku,'-','REF') else c.sku end sku
,sum(case when a.sku is null or a.sku = "" then 0 else a.quantity end) as quantity,
sum(a.total_sales) as sales,
sum(a.total_sales * b.exchange ) as sales_usd
from
(
select *
from db_intl_sales_bi.shopify_order
where financial_status not in ('refunded','voided')
-- where total_sales <> 0
-- and not (`title` REGEXP 'Shokz Running Club')
) a -- 过滤退款订单&无效订单
left join
(
select exchange,month,year,currency
from db_intl_sales_bi.excel_exchange_map
) b
on year(a.purchase_date) = b.year
and month(a.purchase_date) = b.month
and a.currency = b.currency
left join
(
select distinct asin,brand,product_name,product,sku,colour_en,type_2 as product_type
from db_intl_sales_bi.excel_direct_product
) c
on a.sku = c.asin
where date_format(a.purchase_date,'%%Y-%%m-%%d') between date_format(date_add(now(),interval -60 day),'%%Y-%%m-%%d') and date_format(date_add(now(),interval -1 day),'%%Y-%%m-%%d')
and a.site in ('英国','法国')
group by 1,2,3,4,5
)
,tb_dis as
(
select channel_3
,case when country_en = 'UK' then '英国'
when country_en = 'AU' then '澳洲'
when country_en = 'NL' then '荷兰'
when country_en = 'FR' then '法国'
when country_en = 'KR' then '韩国'
when country_en = 'DE' then '德国'
when country_en = 'NL' then '荷兰'
when country_en = 'JP' then '日本'
when country_en = 'IT' then '意大利'
when country_en = 'ES' then '西班牙'
else null end site
,name,theme,product,sku,asin,discount_type,discount,start_time,end_time,comment
from db_intl_sales_bi.excel_dis_list
where channel_3 = "Shopify"
)
select t1.dt,t1.site,t1.product_name,t1.product,t1.sku,t1.quantity,t1.sales,t1.sales_usd
,t2.theme,t2.discount_type,t2.discount,t2.start_time,t2.end_time,t2.comment
from tb_sales t1
left join tb_dis t2
on t1.sku = t2.sku
and t1.dt >= t2.start_time
and t1.dt <= t2.end_time
and t1.site = t2.site
"""
sql_query_au_jp = """
with tb_sales
as
(
select date_format(a.purchase_date,'%%Y/%%m/%%d') dt,
a.site,c.product_name,c.product,c.sku,
sum(case when a.sku is null or a.sku = "" then 0 else a.quantity end) as quantity,
sum(a.total_sales) as sales,
sum(a.total_sales * b.exchange ) as sales_usd
from
(
select *
from db_intl_sales_bi.shopify_order
where financial_status not in ('refunded','voided')
-- where total_sales <> 0
-- and not (`title` REGEXP 'Shokz Running Club')
) a -- 过滤退款订单&无效订单
left join
(
select exchange,month,year,currency
from db_intl_sales_bi.excel_exchange_map
) b
on year(a.purchase_date) = b.year
and month(a.purchase_date) = b.month
and a.currency = b.currency
left join
(
select distinct asin,brand,product_name,product,sku,colour_en,type_2 as product_type
from db_intl_sales_bi.excel_direct_product
) c
on a.sku = c.asin
where date_format(a.purchase_date,'%%Y-%%m-%%d') between date_format(date_add(now(),interval -60 day),'%%Y-%%m-%%d') and date_format(date_add(now(),interval -1 day),'%%Y-%%m-%%d')
and a.site in ('澳洲','日本')
group by 1,2,3,4,5
)
,tb_dis as
(
select channel_3
,case when country_en = 'UK' then '英国'
when country_en = 'AU' then '澳洲'
when country_en = 'NL' then '荷兰'
when country_en = 'FR' then '法国'
when country_en = 'KR' then '韩国'
when country_en = 'DE' then '德国'
when country_en = 'NL' then '荷兰'
when country_en = 'JP' then '日本'
when country_en = 'IT' then '意大利'
when country_en = 'ES' then '西班牙'
else null end site
,name,theme,product,sku,asin,discount_type,discount,start_time,end_time,comment
from db_intl_sales_bi.excel_dis_list
where channel_3 = "Shopify"
)
select t1.dt
,t1.site
,t1.product_name,t1.product,t1.sku,t1.quantity,t1.sales,t1.sales_usd
,t2.theme,t2.discount_type,t2.discount,t2.start_time,t2.end_time,t2.comment
from tb_sales t1
left join tb_dis t2
on t1.sku = t2.sku
and t1.dt >= t2.start_time
and t1.dt <= t2.end_time
and t1.site = t2.site
"""
|