Ich versuche, diese Abfrage funktioniert:PHP, mySQL Summe aus zwei Tabellen
SELECT
IFNULL(SUM(days), 0) AS days
FROM
`table_days`
WHERE task = 1
GROUP BY task
UNION
ALL
SELECT
IFNULL(SUM(total), 0) AS total
FROM
`table_total`
WHERE task = 1
GROUP BY task ;
Ich habe zwei Tabellen:
1. table_days
id task days
==========================
1 1 3.00
2 1 2.00
2. table_total
id task total
==========================
1 3 0.00
Die Abfrage oben teilweise funktioniert, ist das Ergebnis:
stdClass Object
(
[days] => 5.00
)
aber ich möchte das Ergebnis aus der zweiten Tabelle erhalten, auch wenn keine Datensätze gefunden werden. So etwas wie
stdClass Object
(
[days] => 5.00
[total] => 0.00
)
Aufgabe-3 ist absichtlich dort, also, wenn keine Datensätze sind, will ich zurückgeben 0 – Alko
ok, ich verstehe es . Ich repariere Code und jetzt funktioniert es für Aufgabe = 1 in Sekunde wähle –
Immer noch nicht funktioniert. Folgendes bekomme ich: [Wert] => 5.000 [Name] => Tage – Alko