sqlhappen=$@"select sum(t2.cost_tail*t1.quantity_shipped) from dc_base_oms_pick t1
sqlhappen=$@"select sum(t2.cost_logistics*t1.quantity_shipped) from dc_base_oms_pick t1
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_tail > 0
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_logistics > 0
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
varsql=$@"select t1.origin_order_id,pick_order_id,tracking_order_id,t1.bailun_sku,(t2.cost_tail*t1.quantity_shipped) cost_tail,shipping_time from dc_base_oms_pick t1
varsql=$@"select t1.origin_order_id,pick_order_id,tracking_order_id,t1.bailun_sku,(t2.cost_logistics*t1.quantity_shipped) cost_tail,shipping_time from dc_base_oms_pick t1
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_tail > 0
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_logistics > 0
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
varsql=$@"select sum(t2.cost_tail*t1.quantity_shipped) cost_tail from dc_base_oms_pick t1
varsql=$@"select sum(t2.cost_logistics*t1.quantity_shipped) cost_tail from dc_base_oms_pick t1
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_tail > 0
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_logistics > 0
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
varsql=$"select platform_type,origin_order_id,bailun_sku,(cost_tail*bailun_sku_quantity_ordered) as cost_tail,paid_time from dc_base_oms_sku t1 where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1 and cost_logistics>0";
varsql=$"select platform_type,origin_order_id,bailun_sku,(cost_logistics*bailun_sku_quantity_ordered) as cost_tail,paid_time from dc_base_oms_sku t1 where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1 and cost_logistics>0";
varsql="select tb.platform_type,count(tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay',"+(isUSD?"tb.other_to_usd_exchange_rate":"tb.seller_other_exchange_rate")+","+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"))) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") as cost_first,sum(tb.cost_tail*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") profit_total,(sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+")/sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") amount_prepaid from dc_base_oms_order tb ";
varsql="select tb.platform_type,count(tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay',"+(isUSD?"tb.other_to_usd_exchange_rate":"tb.seller_other_exchange_rate")+","+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"))) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") as cost_first,sum(tb.cost_logistics*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") profit_total,(sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+")/sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") amount_prepaid from dc_base_oms_order tb ";
varsql=$"select {str_statistic_col},count(distinct tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"* tb.bailun_sku_quantity_ordered) as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay',"+(isUSD?"tb.other_to_usd_exchange_rate":"tb.seller_other_exchange_rate")+","+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"))*tb.bailun_sku_quantity_ordered) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) as cost_first,sum(tb.cost_tail*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) profit_total,(sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+")/sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) amount_prepaid from dc_base_oms_sku tb ";
varsql=$"select {str_statistic_col},count(distinct tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"* tb.bailun_sku_quantity_ordered) as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay',"+(isUSD?"tb.other_to_usd_exchange_rate":"tb.seller_other_exchange_rate")+","+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"))*tb.bailun_sku_quantity_ordered) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) as cost_first,sum(tb.cost_logistics*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) profit_total,(sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+")/sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) amount_prepaid from dc_base_oms_sku tb ";
//var precolumn = "select website,platform_type as platform,sum(amount_prepaid) amount_prepaid from dc_base_oms_sku where bailun_order_status!='Canceled' and bailun_order_status!='CantHandle' ";
//var precolumn = "select website,platform_type as platform,sum(amount_prepaid) amount_prepaid from dc_base_oms_sku where bailun_order_status!='Canceled' and bailun_order_status!='CantHandle' ";
sql+=" where t1.bailun_order_status!='Canceled' and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp=0 and t1.has_innersale=0 and t1.bailun_interception_status in ('None','Failed') ";
sql+=" where t1.bailun_order_status!='Canceled' and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp=0 and t1.has_innersale=0 and t1.bailun_interception_status in ('None','Failed') ";
sql+=" where t1.bailun_order_status!='Canceled' and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp=0 and t1.has_innersale=0 and t1.bailun_interception_status in ('None','Failed') ";
sql+=" where t1.bailun_order_status!='Canceled' and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp=0 and t1.has_innersale=0 and t1.bailun_interception_status in ('None','Failed') ";
varsql="select origin_order_id,bailun_order_id,platform_type,website,seller_account,paid_time,(amount_sales*seller_order_exchange_rate) amount_sales,(amount_shipping*seller_order_exchange_rate) amount_shipping,(amount_product*seller_order_exchange_rate) amount_product,(amount_tax*seller_order_exchange_rate) amount_tax,(amount_adjustment*seller_order_exchange_rate) amount_adjustment,(amount_gift_wrap*seller_order_exchange_rate) amount_gift_wrap,(amount_refund*seller_order_exchange_rate) amount_refund,amount_prepaid,(cost_promotion*seller_order_exchange_rate) cost_promotion,(cost_platform_fee*seller_order_exchange_rate) cost_platform_fee,cost_product,cost_shipping,cost_package,(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee,(cost_paypal_fee*seller_order_exchange_rate) cost_paypal_fee,(cost_refund_commisson*seller_order_exchange_rate) cost_refund_commisson,cost_handle_bailun,cost_handle_platform,cost_tail,cost_first,profit_total,profit_rate,(cost_total) cost_total from dc_base_oms_order where bailun_order_status='Handling' and bailun_shipping_status!='TotalShipping' and amount_prepaid>0 and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed') ";
varsql="select origin_order_id,bailun_order_id,platform_type,website,seller_account,paid_time,(amount_sales*seller_order_exchange_rate) amount_sales,(amount_shipping*seller_order_exchange_rate) amount_shipping,(amount_product*seller_order_exchange_rate) amount_product,(amount_tax*seller_order_exchange_rate) amount_tax,(amount_adjustment*seller_order_exchange_rate) amount_adjustment,(amount_gift_wrap*seller_order_exchange_rate) amount_gift_wrap,(amount_refund*seller_order_exchange_rate) amount_refund,amount_prepaid,(cost_promotion*seller_order_exchange_rate) cost_promotion,(cost_platform_fee*seller_order_exchange_rate) cost_platform_fee,cost_product,cost_shipping,cost_package,(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee,(cost_paypal_fee*seller_order_exchange_rate) cost_paypal_fee,(cost_refund_commisson*seller_order_exchange_rate) cost_refund_commisson,cost_handle_bailun,cost_handle_platform,cost_logistics as cost_tail,cost_first,profit_total,profit_rate,(cost_total) cost_total from dc_base_oms_order where bailun_order_status='Handling' and bailun_shipping_status!='TotalShipping' and amount_prepaid>0 and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed') ";
varsqlcount="select sum(amount_sales*seller_order_exchange_rate) amount_sales,sum(amount_shipping*seller_order_exchange_rate) amount_shipping,sum(amount_product*seller_order_exchange_rate) amount_product,sum(amount_tax*seller_order_exchange_rate) amount_tax,sum(amount_adjustment*seller_order_exchange_rate) amount_adjustment,sum(amount_gift_wrap*seller_order_exchange_rate) amount_gift_wrap,sum(amount_refund*seller_order_exchange_rate) amount_refund,sum(amount_prepaid) amount_prepaid,sum(cost_promotion*seller_order_exchange_rate) cost_promotion,sum(cost_platform_fee*seller_order_exchange_rate) cost_platform_fee,sum(cost_product) cost_product,sum(cost_shipping) cost_shipping,sum(cost_package) cost_package,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee,sum(cost_paypal_fee*seller_order_exchange_rate) cost_paypal_fee,sum(cost_refund_commisson*seller_order_exchange_rate) cost_refund_commisson,sum(cost_handle_bailun) cost_handle_bailun,sum(cost_handle_platform) cost_handle_platform,sum(cost_tail) cost_tail,sum(cost_first) cost_first,sum(profit_total) profit_total,sum(cost_total) cost_total from dc_base_oms_order where bailun_order_status='Handling' and bailun_shipping_status!='TotalShipping' and has_scalp=0 and has_innersale=0 and amount_prepaid>0 and bailun_interception_status in ('None','Failed') ";
varsqlcount="select sum(amount_sales*seller_order_exchange_rate) amount_sales,sum(amount_shipping*seller_order_exchange_rate) amount_shipping,sum(amount_product*seller_order_exchange_rate) amount_product,sum(amount_tax*seller_order_exchange_rate) amount_tax,sum(amount_adjustment*seller_order_exchange_rate) amount_adjustment,sum(amount_gift_wrap*seller_order_exchange_rate) amount_gift_wrap,sum(amount_refund*seller_order_exchange_rate) amount_refund,sum(amount_prepaid) amount_prepaid,sum(cost_promotion*seller_order_exchange_rate) cost_promotion,sum(cost_platform_fee*seller_order_exchange_rate) cost_platform_fee,sum(cost_product) cost_product,sum(cost_shipping) cost_shipping,sum(cost_package) cost_package,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee,sum(cost_paypal_fee*seller_order_exchange_rate) cost_paypal_fee,sum(cost_refund_commisson*seller_order_exchange_rate) cost_refund_commisson,sum(cost_handle_bailun) cost_handle_bailun,sum(cost_handle_platform) cost_handle_platform,sum(cost_logistics) cost_tail,sum(cost_first) cost_first,sum(profit_total) profit_total,sum(cost_total) cost_total from dc_base_oms_order where bailun_order_status='Handling' and bailun_shipping_status!='TotalShipping' and has_scalp=0 and has_innersale=0 and amount_prepaid>0 and bailun_interception_status in ('None','Failed') ";
varsql="select tb.platform_type,count(distinct tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"* tb.bailun_sku_quantity_ordered) as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay',"+(isUSD?"tb.other_to_usd_exchange_rate":"tb.seller_other_exchange_rate")+","+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"))*tb.bailun_sku_quantity_ordered) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) as cost_first,sum(tb.cost_tail*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) profit_total,(sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+")/sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) amount_prepaid from dc_base_oms_sku tb ";
varsql="select tb.platform_type,count(distinct tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"* tb.bailun_sku_quantity_ordered) as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay',"+(isUSD?"tb.other_to_usd_exchange_rate":"tb.seller_other_exchange_rate")+","+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"))*tb.bailun_sku_quantity_ordered) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) as cost_first,sum(tb.cost_logistics*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+"*tb.bailun_sku_quantity_ordered) cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) profit_total,(sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+")/sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+"*tb.bailun_sku_quantity_ordered) amount_prepaid from dc_base_oms_sku tb ";