martin: MYSQL Abfrage:Summieren

Hallo,

ich habe ein Problem mit dem Summieren von Tabelleneinträgen. Ich habe eine Tabelle, wie z.B.

Anzahl Art
1      Apfel
1      Birne
2      Apfel

und möchte jetzt die Anzahl der Äpfel, also 3, ... ermitteln.

Die Abfrage:

SELECT Art, count( Art ) AS C FROM tabelle GROUP BY Art

funktioniert schon mal ganz gut allerdings wird die Anzahl nicht miteinbezogen.

SELECT Art, count( Art * Anzahl ) AS C FROM tabelle GROUP BY Art

funktioniert nicht.

Wer kann mir helfen?

Gruss
martin

  1. Hi martin

    SELECT Art, count( Art ) AS C FROM tabelle GROUP BY Art

    funktioniert schon mal ganz gut allerdings wird die Anzahl nicht miteinbezogen.

    Natürlich nicht, dazu ist sum da.

    SELECT Art, sum(Anzahl) AS C FROM tabelle GROUP BY Art.

    Du solltest dir das entsprechende Kapitel in der MySQL Doku mal anschauen.

    Gruss Daniela

    1. Hallo Daniela,

      vielen Dank für die schnelle Hilfe.

      Grüsse
      martin