sqlserver 佣金分析
时间:2022-03-15 15:13
片段:
declare @month VARCHAR(7) declare @yaoqingma_pid VARCHAR(7) set @month= N‘2019-07‘ set @yaoqingma_pid= N‘RSNOAP‘ -- 一级订单 SELECT ‘‘ AS id, a.login_name , a.yaoqingma_self , a.yaoqingma , o.effect_first AS effect_sum, o.yongjin_first, 1 , 1, @yaoqingma_pid FROM dbo.sys_user a LEFT JOIN (SELECT SUM(effect_first)effect_first,SUM(yongjin_first)yongjin_first,userid FROM dbo.sys_taobao_order where SUBSTRING(order_time ,1,7) = @month GROUP BY userid ) o ON a.login_name = o.userid WHERE [yaoqingma_self] = @yaoqingma_pid UNION ALL -- 二级订单 SELECT ‘‘ AS id, a.login_name , a.yaoqingma_self , a.yaoqingma , o.effect_second AS effect_sum, o.yongjin_second, 1 , 0, @yaoqingma_pid FROM dbo.sys_user a LEFT JOIN (SELECT SUM(effect_second)effect_second,SUM(yongjin_second)yongjin_second,userid FROM dbo.sys_taobao_order where SUBSTRING(order_time ,1,7) = @month GROUP BY userid ) o ON a.login_name = o.userid WHERE [yaoqingma] = @yaoqingma_pid UNION ALL -- 三级订单 SELECT ‘‘ AS id, a.login_name , a.yaoqingma_self , a.yaoqingma , o.effect_third AS effect_sum, o.yongjin_third, 2 , 0, @yaoqingma_pid FROM dbo.sys_user a INNER join sys_user b on a.yaoqingma=b.yaoqingma_self LEFT JOIN (SELECT SUM(effect_third)effect_third,SUM(yongjin_third)yongjin_third,userid FROM dbo.sys_taobao_order where SUBSTRING(order_time ,1,7) = @month GROUP BY userid ) o ON a.login_name = o.userid WHERE a.yaoqingma IN(SELECT yaoqingma_self FROM dbo.sys_user WHERE yaoqingma=@yaoqingma_pid)
declare @month VARCHAR(7) declare @yaoqingma_pid VARCHAR(7) set @month= N‘2019-08‘ set @yaoqingma_pid= N‘RSNOAP‘ select * FROM willpay_report where SUBSTRING(order_month ,1,7) = @month -- and login_name =‘18632171962‘ select * FROM willpay_report where SUBSTRING(order_month ,1,7) = ‘2019-08‘ and login_name =‘18632171962‘ SELECT SUM(isnull(effect_sum,0)) FROM dbo.willpay_report WHERE other1=@yaoqingma_pid AND is_leader=‘0‘ SELECT SUM(isnull(effect_sum,0)) FROM dbo.willpay_report WHERE other1=@yaoqingma_pid AND is_leader=‘0‘ and order_month = @month
佣金合计:
SELECT ( SUM(isnull(yongjin_sum, 0)) - isnull( ( SELECT SUM( isnull(withdraw_reality_total, 0) + isnull(withdraw_charge, 0) ) FROM withdrawal WHERE ( status = ‘3‘ OR status = ‘2‘ OR status = ‘1‘ ) AND userid = ‘18632171962‘ ), 0 )+ ISNULL((SELECT SUM( isnull(withdraw_reality_total, 0) + isnull(withdraw_charge, 0) ) FROM withdrawal WHERE ( status = ‘3‘ OR status = ‘2‘ OR status = ‘1‘ ) AND userid = ‘18632171962‘),0) ) yongjin_sum FROM dbo.willpay_report WHERE is_leader = ‘1‘ AND is_jiesuan = ‘1‘ AND login_name =‘18632171962‘ --and order_month=‘2019-07‘ SELECT SUM(isnull(yongjin_sum, 0)) yongjin_sum FROM dbo.willpay_report WHERE is_leader = ‘1‘ AND is_jiesuan = ‘1‘ AND login_name =‘18632171962‘ SELECT SUM(isnull(effect_sum, 0)) effect_sum FROM dbo.willpay_report WHERE is_leader = ‘1‘ AND is_jiesuan = ‘1‘ AND login_name =‘18632171962‘ SELECT isnull(effect_sum, 0)effect_sum, isnull(yongjin_sum, 0)yongjin_sum,is_jiesuan,order_month FROM dbo.willpay_report WHERE is_leader = ‘1‘ AND isnull(is_jiesuan,0) = 0 AND login_name =‘18632171962‘