SET @MONTH_MIN = 202103;
SET @MONTH_MAX = 202104;

SELECT
	S.CALC_MONTH AS 结算月,
	U.USER_NAME AS 会员编号,
	U.REAL_NAME AS 会员姓名,
	U2.USER_NAME AS 推荐人编号,
	U2.REAL_NAME AS 推荐人姓名,
	D.LEVEL_NAME AS 结算时会员级别,
	E.LEVEL_NAME AS 结算时会员聘级,
	S.AMOUNT_PCS AS 个人销售额,
	S.AMOUNT_PSS AS 团队销售额,
	DATE_FORMAT(FROM_UNIXTIME(S.CREATED_AT),'%Y-%m-%d %H:%i:%s') AS 创建时间
FROM
	AR_PERF_STANDARD S
	LEFT JOIN AR_USER U ON U.ID = S.USER_ID
	LEFT JOIN AR_USER_RELATION_NEW R ON R.USER_ID = S.USER_ID
	LEFT JOIN AR_USER U2 ON U2.ID = R.PARENT_UID
	LEFT JOIN AR_DECLARATION_LEVEL D ON D.ID = S.LAST_DEC_LV
	LEFT JOIN AR_EMPLOY_LEVEL E ON E.ID = S.LAST_EMP_LV
	WHERE S.CALC_MONTH >= @MONTH_MIN AND S.CALC_MONTH <= @MONTH_MAX