SET @CALC_MONTH = 202106 ;

SELECT
	U.USER_NAME AS 会员编号,
	U.REAL_NAME AS 会员姓名,
	(M.VIP_PV_1L_ZC + IFNULL(A.VIP_SURPLUS_1L_ZC,0)) AS 一市场新增加结余,
	(M.VIP_PV_2L_ZC + IFNULL(A.VIP_SURPLUS_2L_ZC,0)) AS 二市场新增加结余,
	(M.VIP_PV_3L_ZC + IFNULL(A.VIP_SURPLUS_3L_ZC,0)) AS 三市场新增加结余
FROM
	ar_perf_month M
	LEFT JOIN ar_user U ON U.ID = M.USER_ID
	LEFT JOIN (SELECT
		AU.ID,
		PM.VIP_SURPLUS_1L_ZC,
		PM.VIP_SURPLUS_2L_ZC,
		PM.VIP_SURPLUS_3L_ZC
	FROM
		ar_perf_month PM
		LEFT JOIN ar_user AU ON AU.ID = PM.USER_ID
		WHERE PM.CALC_MONTH = @CALC_MONTH - 1
	) A ON A.ID = M.USER_ID
	WHERE M.CALC_MONTH = @CALC_MONTH