Download order_sql_code.py from pengyuyan1222/instock_warning_GUI_cloud: direct link, hf CLI and curl.
- Browser
- Download file 5.54 kB
-
https://huggingface.co/spaces/pengyuyan1222/instock_warning_GUI_cloud/resolve/main/order_sql_code.py
- Command line
-
hf download hf://spaces/pengyuyan1222/instock_warning_GUI_cloud/order_sql_code.py
-
curl -L -o order_sql_code.py https://huggingface.co/spaces/pengyuyan1222/instock_warning_GUI_cloud/resolve/main/order_sql_code.py
5.54 kB
| 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 | |
| """ | |