SQL-Abfrage zur Berechnung Summe pro Monat als Spalte

Ich bin stecken geblieben auf einer SQL-Abfrage. Ich benutze PostgreSQL. Ich brauche, um die Summe für jeden Monat für alle Staaten.

table A 
--------------------------------------------------------
created    |    Name    | Agent_id  | Total
--------------------------------------------------------
3/14/2013  |    Harun   | 1A        |  5                
3/14/2013  |    Hardi   | 2A        | 20
4/14/2013  |    Nizar   | 3A        | 30
5/14/2013  |    moyes   | 4A        | 20

table B 
----------------------------
Agent_id| state_id
----------------------------
1A      | 1
2A      | 1 
3A      | 1
4A      | 2

table C 
----------------------------
state_id   |    State   
----------------------------
   1       |    Jakarta 
   2       |    Singapore
   3       |    Kuala lumpur

GEWÜNSCHTE ERGEBNIS:

-----------------------------------------------------------------------------------------------
No  |State          | Januari | February | March | April | Mei  ... December| Total
-----------------------------------------------------------------------------------------------
1   |Jakarta        |0        |0         |25     |  30   |  0   ...         | 55
2   |Singapore      |0        |0         | 0     |   0   | 20   ...         | 20
3   |Kuala Lumpur   |0        |0         | 0     |   0   |  0   ...         |  0
InformationsquelleAutor muhnizar | 2013-10-04
Schreibe einen Kommentar