SELECT
	A.USER_NAME,
	A.REAL_NAME,
	A.LEVEL_NAME,
	A.PV_FX,
	A.XIAOYEJI
FROM
(SELECT
	U.USER_NAME,
	U.REAL_NAME,
	D.LEVEL_NAME,
	SUM(O.`PV合计`) AS PV_FX,
	VIPXIAOYEJI(U.USER_NAME, 202104) AS XIAOYEJI
FROM
	`临时会员` F
	LEFT JOIN ar_user U ON U.USER_NAME = F.`会员编号`
	LEFT JOIN ar_declaration_level D ON D.ID = U.DEC_LV
	LEFT JOIN zr_order_vw O ON O.`会员编号` = F.`会员编号` AND O.`订单类型` <> '报单' AND O.`月份` = 202104
	GROUP BY U.USER_NAME)A
	WHERE A.PV_FX>= 300 AND A.XIAOYEJI >= 9800 AND (A.LEVEL_NAME = '金钻会员' OR A.LEVEL_NAME = 'VIP会员')
	
	
	
