您在 SELECT 语句中使用 T.id 来引用 iw_seaservice_apply 表的 id 列,但 T 并没有被定义为该表的别名,因此产生了 "Unknown column 'T.id' in 'field list'" 的错误。

您需要在 SELECT 语句中添加别名 T 来定义表 iw_seaservice_apply 的别名,然后使用 T.id 来引用该表的 id 列。例如:

SELECT MAX(T.id) AS 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 talentName, a.status AS applyStatus, IFNULL(d.has_withdraw,0) AS hasWithdraw
FROM iw_seaservice_apply T
LEFT JOIN iw_seaservice b ON T.seaservice_id = b.id
LEFT JOIN iw_company c ON b.company_id = c.id
LEFT JOIN iw_seaservice_completion_apply d ON T.id = d.seaservice_apply_id
LEFT JOIN iw_talent_user e ON b.talent_user_id = e.id
${ew.customSqlSegment}
<if test="minPayAmount != null">
    AND pay_amount &gt;= #{minPayAmount}
</if>
<if test="maxPayAmount != null">
    AND pay_amount &lt;= #{maxPayAmount}
</if>
<if test="applyStatus != null">
    AND applyStatus = #{applyStatus}
</if>
<if test="companyName != null and companyName != '' ">
    AND companyName LIKE '${companyName}%'
</if>
GROUP BY seaservice_id
ORDER BY create_time DESC, seaservice_id DESC

在这个示例中,我们为 iw_seaservice_apply 表添加了别名 T,并使用 T.id 来引用该表的 id 列。这样就可以解决 Unknown column 'T.id' in 'field list' 错误。

MySQL 报错

原文地址: https://www.cveoy.top/t/topic/oky7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录