mysql 两张表取总合 和差集
SELECT
id AS kid,
NAME,
IF (t1.kpi, t1.kpi, 0) AS kpi,
t1.sort,
STATUS,
t1.kpi_id
FROM
form_kpi_name
LEFT JOIN (
SELECT
kpi_id AS i,
kpi,
sort,
username,
id AS kpi_id
FROM
faw_form_kpi
WHERE
username = '123'
) AS t1 ON form_kpi_name.id = t1.i
WHERE
form_kpi_name.type = 0
如果是取差集 可以在 加 t1表或form_kpi_name 表的的关联id is null 如:where t1.i is null;