werte aller spalten addieren

xtraMen

Erfahrenes Mitglied
Hallo Leute,

wie muss ich Abfragen wenn ich alle Werte einer Spalte in einer Db addieren möchte.
Mit select count(*) as count from.... zähle ich ja nur die Anzahl der Einträge....

DAnke für den Tipp.
 
Ja das hab ich schon getan.
Ich hab das auch mit der Funktion probiert, aber ich bekomme eine Fehlermeldung.

PHP:
 $gesamt_query = tep_db_query("select o.orders_id, o.date_purchased, o.delivery_name, o.billing_name, sum(ot.text) as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . $_GET['cID']. "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id");
      $gesamt = tep_db_fetch_array($gesamt_query);

Die Meldung lautet:

PHP:
1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

select o.orders_id, o.date_purchased, o.delivery_name, o.billing_name, sum(ot.text) as order_total, s.orders_status_name from orders o, orders_total ot, orders_status s where o.customers_id = '7' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '2' order by orders_id

[TEP STOP]

Gruss
 
Bestimmte Funktionen (z. B. MIN(), MAX(), COUNT(), etc.) können zusammen mit anderen Ausdrücken nur in Verbindung mit der GROUP BY-Klausel benutzt werden. Siehe dazu Funktionen zur Benutzung bei GROUP BY-Klauseln.
Dass heißt entweder musst du die Summe in einer eigenen Abfrage abfragen oder die Abfrage gruppieren.
 
Zurück