1
SELECT *, count(spieler) as 'Anzahl' 

FROM spieler, teilnehmer, durchfuehrung 

WHERE spieler.id = teilnehmer.spieler and teilnehmer.istErschienen = 1 and teilnehmer.durchfuehrung = durchfuehrung.id and durchfuehrung.wurdeUeberprueft = 1  

GROUP BY  teilnehmer.spieler

ORDER BY 'Anzahl' DESC;

ORDER BY is useless in this way... Please help me to correct this mysql Query, so that the Alias Anzahl ist ordered desc....

  • 1
    [When to use single quotes, double quotes, and backticks in MySQL](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – fancyPants Apr 03 '17 at 09:53
  • Don't use `SELECT * ... GROUP BY x` -- the values in `*` will be _unpredictable_. – Rick James Apr 30 '17 at 17:36

2 Answers2

2

I think you should not quote your alias Anzahl

You should be carefully, if you are using aggregate Functions like count() with a SELECT *. You can't group it very well and it is forbidden by convention.

Better try something like this:

SELECT 
    spieler.id, 
    teilnehmer.durchfuehrung,
    COUNT(*) AS anzahl 
FROM 
    spieler,
    teilnehmer,
    durchfuehrung 
WHERE
    spieler.id = teilnehmer.spieler
AND
    teilnehmer.istErschienen = 1 
AND
    teilnehmer.durchfuehrung = durchfuehrung.id
AND
    durchfuehrung.wurdeUeberprueft = 1 
GROUP BY 
    spieler.id, 
    teilnehmer.durchfuehrung
ORDER BY 
    anzahl DESC;
2

you should use this

   order by  count(spieler)
krishn Patel
  • 2,579
  • 1
  • 19
  • 30