我正在寻找一种可能性(重新)使用一个 SQL 选择结果来获取同一查询内不同子选择的值
首先,我应该通过如下选择获取 $ValueToUse:
SELECT `cb_campaignid` as ValueToUse FROM `#__team_groups` WHERE `id` = '$Value'
对于“ValueToUse”结果,如果可能的话,我想在同一个 SQL 查询语句中进行下一个选择。
SELECT coalesce (nullif (SUM(Amount), ''), '0') as general_amount, (SELECT SUM(c.cb_stand) FROM #__employees c, #__team_users u where c.user_id=u.user_id and u.group=(select id from #__team_groups where cb_campaignid='$ValueToUse')) as teamleden_tussenstand, (select title from #__customer_campaigns where id='$ValueToUse') as title, (select id from #__team_groups where cb_campaignid='$ValueToUse') as groupID, (select goal from #__customer_campaigns where id='$ValueToUse') as goal FROM #__customer_payments WHERE published = 1 and campaign_id = '$ValueToUse'
获得这些结果的最佳方法是什么?
使用第一个结果作为变量怎么样?