Heim > Fragen und Antworten > Hauptteil
Ich suche nach einer Möglichkeit, die Ergebnisse einer SQL-Auswahl (wieder)zu verwenden, um die Werte verschiedener Unterauswahlen innerhalb derselben Abfrage zu erhalten
Zuerst sollte ich $ValueToUse erhalten, indem ich Folgendes auswähle:
SELECT `cb_campaignid` as ValueToUse FROM `#__team_groups` WHERE `id` = '$Value'
Für das Ergebnis „ValueToUse“ möchte ich die nächste Auswahl möglichst in derselben SQL-Abfrageanweisung treffen.
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'
Was ist der beste Weg, diese Ergebnisse zu erzielen?
P粉6455691972024-04-03 17:38:56
使用第一个结果作为变量怎么样?
SELECT @ValueToUse:= (SELECT `cb_campaignid` as ValueToUse FROM `#__team_groups` WHERE `id` = '$Value'); 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;