多个表关联出现了重复数据的问题sql 因为需要考虑多个情况,考虑多个情况。批次号和活动编号。写表关联的时候,可以写多个字段,都加进去。 on a.`notifySettingKey`=ex.notifyKey and a.batchNo=ex.batchNo

select n.campaignTitle,a.type,n.`key`,sum(a.totalCount),a.succuesCount,a.failedCount,a.pushedAt,a.finishedAt,a.batchNo from
xxx.push_records a
left join xxx.notify_setting_new n
on a.`notifySettingKey`=n.notifyKey
left join xxx.notify_except_total_new ex
on a.`notifySettingKey`=ex.notifyKey and a.batchNo=ex.batchNo
left join xxx.notify_time_setting_new t on left(a.`notifySettingKey`,4)=t.notifySettingKey
where a.notifySettingKey
is not null and
locate('notify', a.`notifySettingKey`) and n.notifyKey is not null and t.isOneTimes=0
<if test="params.default != null and params.default != ''">
<![CDATA[ and 2 >= DATEDIFF(NOW(),a.pushedAt) ]]>
</if>
<if test="params.campaignTitle != null and params.campaignTitle != ''">
and n.campaignTitle
LIKE "%"#{params.campaignTitle}"%"
</if>
posted @ 2021-09-28 11:31  夏之  阅读(368)  评论(0编辑  收藏  举报