如何过滤重复的海服务申请数据?获取最新的申请信息
可以在外层包裹一层子查询,使用 DISTINCT 关键字去重,并按照 id 倒序排序,取最新的一条申请数据。示例代码如下:
SELECT DISTINCT(T.seaservice_id), T.*
FROM (
SELECT a.id,b.id AS seaservice_id,a.create_time,b.talent_user_id,b.company_id,b.title,b.pay_amount,b.payment_way,b.currency,b.completion_time,b.sea_service_status,b.service_address,
COALESCE(c.short_name_cn,e.realname, e.nickname, e.username) AS companyName,a.status AS applyStatus,IFNULL(d.has_withdraw,0) as hasWithdraw
FROM iw_seaservice_apply a LEFT JOIN iw_seaservice b ON a.seaservice_id = b.id LEFT JOIN iw_company c ON b.company_id = c.id
LEFT JOIN iw_seaservice_completion_apply d ON a.id = d.seaservice_apply_id LEFT JOIN iw_talent_user e ON b.talent_user_id = e.id
) T ${ew.customSqlSegment}
<if test="minPayAmount != null">
AND pay_amount >= #{minPayAmount}
</if>
<if test="maxPayAmount != null">
AND pay_amount <= #{maxPayAmount}
</if>
<if test="applyStatus != null">
AND applyStatus = #{applyStatus}
</if>
<if test="companyName != null and companyName != '' ">
AND companyName LIKE '${companyName}%'
</if>
ORDER BY T.id DESC
原文地址: http://www.cveoy.top/t/topic/oi0t 著作权归作者所有。请勿转载和采集!