SELECT
case when a.value is null || a.`value` = '' || LOCATE('nocheck', a.VALUE) > 0
then ''
ELSE
a.value
end as bgy_contract_project ,
case when c.value is null || c.`value` = '' || LOCATE('nocheck', c.VALUE) > 0
then ''
ELSE
c.value
end as contract_name
FROM
ar_approve_entry_result a
LEFT JOIN ar_approve_entry_result c ON a.approve_result_uuid = c.approve_result_uuid
AND c.entry_UUID = 'AREN1295'
INNER JOIN (
SELECT
b.uuid,
b.pay_comfirm_uuid
FROM
ar_approve_result b
WHERE
b.sys_status = 1
AND b.pay_comfirm_uuid = '432d9912f3f14d58a88251d9cd739a6f'
ORDER BY
b.db_create_sys_time DESC
LIMIT 0,1
) b ON a.approve_result_uuid = b.uuid
WHERE
a.sys_status = 1
AND a.entry_UUID = 'AREN17324' ;
这个sql分析:
第一点: A LEFT JOIN B (A 表数据一定存在 ,然后 B 表的数据 不一定存在,
所以在 on 后面 紧跟 B表的关联 and c.entry_UUID = 'AREN1295' 这个 关联条件,
AREN1295是 履约文件节点的合同名称/工程名称/项目名称,因为这样,即使 B表数据没有,也没有关系,
而 在WHERE 后面加这个AND a.entry_UUID = 'AREN17324' 采购订单的工程名称/项目名称 ,是因为这个是一定存在的)
第二点:case when 的使用
第三点:LOCATE('nocheck', a.VALUE) > 0 使用,这个 的使用 意思是,当 a.VALUE 的值为 nocheck 的时候,
LOCATE()这个方法的返回值,就是 大于0 ,接着 就用它作为了 判断条件