0

Ok, I hope this time I ask my answer in a better way :) Sorry for the previous one.

I have this query:

SELECT getal,
    COUNT(*) AS aantalmaal,
    IF(aantalmaal > 99, 4,
    IF(aantalmaal > 66, 3,
    IF(aantalmaal > 33, 2, 1))) AS xkeerinzetten
FROM gevallengetallen

I get the error message: "#1054 - Unknown column 'aantalmaal' in 'field list'"

If anyone has an idea, thank you in advance!

Erik
  • 85
  • 8
  • 2
    You can't refer to an alias in the select list of the same query. Either do `COUNT(*)` in a subquery, or use `COUNT(*)` in the `IF` functions. – Barmar Nov 10 '22 at 20:40
  • Also, use `CASE` for a multi-way condition, instead of nested `IF`. – Barmar Nov 10 '22 at 20:41

0 Answers0