有 3 个不同的表,从第一个表中我得到“contact_id”,基于此,我想对接下来的 2 个表进行 SUM,然后减去表,如下面的代码所示。
我正在尝试将第一个查询的结果“contact_id”用于以下查询
SELECT (
SELECT `id`
FROM `civicrm_contact`
WHERE `first_name` LIKE 'test2'
) AS contact_id
==================================================== ===========
SELECT (
SELECT SUM(`total_amount`)
FROM `civicrm_contribution`
WHERE `contact_id`=
)
-
(
SELECT SUM(`fee_amount`)
FROM `civicrm_participant`
WHERE `contact_id`=
) As RemainingPoints