Ich brauche ein wenig Hilfe mit MySQL in SQL oder PHP auswählen. Meine Situation: habe ich eine SQL-Tabelle wie dieseMySQL/PHP Zeilen-für-Zeile-Werte zusammenführen
ID | organization_ID | Investment | investment_curr | paid | paid_curr | effective_from | Effective_to
1 | 195001 | 5000 | EUR | NULL | EUR | 2010-06-23 | NULL
2 | 195001 | NULL | EUR | 5000 | EUR | 2010-06-23 | NULL
3 | 195001 | 2000 | SKK | NULL | SKK | 2007-08-01 | 2010-06-22
4 | 195001 | NULL | SKK | 2000 | SKK | 2007-08-01 | 2010-06-22
Jetzt habe ich php select (joomla), wenn Sie die Werte von organization_id
$query_rpo_organization_equity_entries = $db->getQuery(true);
$query_rpo_organization_equity_entries
->select(array('organization_id',
'investment_amount',
'investment_currency',
'paid_amount',
'paid_currency',
'effective_from',
'effective_to'
))
->from($db->quoteName('rpo_organization_equity_entries'))
->where($db->quoteName('organization_id') . ' = '. $db->quote($rpo_id))
->order(($db->quoteName('effective_to') . ' IS NOT NULL'), $db->quoteName('effective_to') . ' DESC ');
$db->setQuery($query_rpo_organization_equity_entries);
$query_rpo_organization_equity_entries = $db->loadObjectList();
Dann foreach Im Aufruf
foreach($query_rpo_organization_equity_entries as $rpo_organization_equity_entries) {}
Alles funktioniert richtig, aber nicht so, wie ich es brauche. Diese foreach
gibt 4 Arrays zurück, aber ich brauche Reihen zusammenführen/kombinieren nach Spalten "effektiv_von" UND "effektiv_to" (Wenn sie die gleichen Werte haben. Und organisation_id natürlich). Damit ich Reihe kombinieren mit IDs 1 und 2, und Zeilen mit IDs 3 und 4, und statt 4-Arrays habe ich nur 2 kombinieren/Merge-Arrays wie folgt
XY | 195001 | 5000 | EUR | 5000 | EUR | 2010-06-23 | NULL
XY | 195001 | 2000 | SKK | 2000 | SKK | 2007-08-01 | 2010-06-22
wie soll ich es tun? ist es besser, die SQL und dann in PHP zu lösen?
thx
Siehe https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-very-simple- sql-query – Strawberry