MySQL Lists are EOL. Please join:

List:German« Previous MessageNext Message »
From:BG Date:January 15 2019 4:15pm
Subject:AW: GROUP BY + COUNT
View as plain text  
Nochmals zur Verdeutlichung ..

Tabelle: autos

id | a1	| a2 | a3
------------------------------------------
1 | 1 | 0 | 0
2 | 0 | 1 | 0
3 | 1 | 1 | 1
4 | 1 | 1 | 0

Ergebnis soll sein:

Mercedes 3
BMW 3
Ford 1

---

Es soll anstatt dieser UNION Query nur noch eine Abfrage erfolgen ..
 
SELECT 'Mercedes' AS marke, COUNT(autos.id) FROM autos WHERE a1=1 UNION
SELECT 'BMW' AS marke, COUNT(autos.id) FROM autos WHERE a2=1 UNION
SELECT 'Ford' AS marke, COUNT(autos.id) FROM autos WHERE a3=1

Grüße
Bert

Thread
GROUP BY + COUNTBG15 Jan
  • AW: GROUP BY + COUNTBG15 Jan
    • AW: GROUP BY + COUNTBG15 Jan
      • Re: GROUP BY + COUNTMartin Wildgruber15 Jan
        • AW: GROUP BY + COUNTBG15 Jan
    • Re: GROUP BY + COUNTFrank Rasche15 Jan