sqlserver 佣金分析

Posted hoge66

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver 佣金分析相关的知识,希望对你有一定的参考价值。

片段:

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‘

  

以上是关于sqlserver 佣金分析的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver2019分析服务安装失败,无法启动服务

sql server 性能调优之 逻辑内存消耗最大资源分析1 (自sqlserver服务启动以后)

Oracle/SQLServer 中的分析函数高级教程 [关闭]

oracle有没有类似sqlserver的查询分析器的工具呢本身

sqlserver 抓取所有执行语句 SQL语句分析 死锁 抓取

在sqlserver 2008 怎么配置才可以正常支持lead和lag分析函数