+ Antworten
Ergebnis 1 bis 2 von 2

Thema: [MySQL] Problem mit Union

  1. #1
    TP-Veteran alexf812 macht alles soweit korrekt Avatar von alexf812
    Registriert seit
    Sep 2004
    Beiträge
    1.370

    [MySQL] Problem mit Union

    Hi,

    folgende Abfrage:

    (SELECT COUNT(*) anzahl, x as col
    FROM table
    GROUP BY col_1)
    UNION
    (SELECT COUNT(*) anzahl, y as col
    FROM table
    GROUP BY col_2)
    ORDER BY col ASC

    Jetzt würde ich die spalte col erneut gruppieren + count... geht sowas?

  2. #2
    TP-Veteran alexf812 macht alles soweit korrekt Avatar von alexf812
    Registriert seit
    Sep 2004
    Beiträge
    1.370
    vielleicht interessiert es jemand..hier mal die lösung:

    Code:
    SELECT SUM(anzahl) as gesamt,col FROM (
    		(SELECT COUNT(*) anzahl, col_1 as col
    			FROM table
    			GROUP BY col_1)
    		UNION
    			(SELECT COUNT(*) anzahl, col_2 as col
    				FROM table
    				GROUP BY col_2)) as t
    		GROUP BY col
    		ORDER BY gesamt DESC, col ASC

+ Antworten

Stichworte

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

     

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51