我正在使用以下查询从表中选择事务:
SELECT t.*
FROM transactions AS t
WHERE t.id IN
(
SELECT t2.id
FROM `virtual_account-account` AS vaa
LEFT JOIN transactions AS t2
ON t2.account = vaa.account
WHERE vaa.virtual_account = 3
)
AND t.id IN
(
SELECT tt.transaction
FROM `virtual_account-tag` AS vat
LEFT JOIN `transaction-tag` AS tt
ON tt.tag = vat.tag
WHERE vat.virtual_account = 3
)
ORDER BY t.date
但是,我想对此进行修改,例如,如果联结表virtual_account-account
不包含任何联结 where ,则应忽略vaa.virtual_account = 3
相应的条件。t.id IN (...)
到目前为止,我还没有找到解决方案,所以任何帮助都将不胜感激。