<select id="totalPageInfo" resultType="com.kwan.springbootkwan.entity.dto.CsdnTotalIncomeDTO">
SELECT t1.receiver_nick_name AS nickName
, SUM(t1.received_money) AS amount
FROM table_1 t1 left join table_2 t2
on t1.order_no = t2.order_no
AND t1.community_id=t2.community_id
AND t1.post_id=t2.post_id
WHERE 1 = 1
<if test="query.startDate != null">
AND t1.receive_time <![CDATA[>= #{query.startDate}]]>
AND t2.create_time <![CDATA[>= #{query.startDate}]]>
</if>
<if test="query.endDate != null">
AND t1.receive_time <![CDATA[<= #{query.endDate}]]>
AND t2.create_time <![CDATA[<= #{query.endDate}]]>
</if>
GROUP BY nickName
ORDER BY amount DESC
</select>
二.解决方案
1.SQL 如下
apl复制代码
<select id="totalPageInfo" resultType="com.kwan.springbootkwan.entity.dto.CsdnTotalIncomeDTO">
SELECT t1.receiver_nick_name AS nickName
, SUM(t1.received_money) AS amount
FROM table_1 t1 left join table_2 t2
on t1.order_no = t2.order_no
<![CDATA[
AND t1.community_id <=> t2.community_id
AND t1.post_id<=> t2.post_id
]]>
WHERE 1 = 1
<if test="query.startDate != null">
AND t1.receive_time <![CDATA[>= #{query.startDate}]]>
AND t2.create_time <![CDATA[>= #{query.startDate}]]>
</if>
<if test="query.endDate != null">
AND t1.receive_time <![CDATA[<= #{query.endDate}]]>
AND t2.create_time <![CDATA[<= #{query.endDate}]]>
</if>
GROUP BY nickName
ORDER BY amount DESC
</select>
SELECT
t1.receiver_nick_name AS nickName,
SUM(t1.received_money) AS amount
FROM
table_1 t1
LEFT JOIN
table_2 t2 ON t1.order_no = t2.order_no
AND t1.community_id <=> t2.community_id
AND t1.post_id <=> t2.post_id
WHERE
1 = 1
<if test="query.startDate != null">
AND t1.receive_time <![CDATA[>= #{query.startDate}]]>
AND t2.create_time <![CDATA[>= #{query.startDate}]]>
</if>
<if test="query.endDate != null">
AND t1.receive_time <![CDATA[<= #{query.endDate}]]>
AND t2.create_time <![CDATA[<= #{query.endDate}]]>
</if>
GROUP BY
nickName
ORDER BY
amount DESC