I have seen a query on https://mode.com/sql-tutorial/sql-case/ where within a GROUP BY a constant is used. Here ist the relevant excerpt:
SELECT CASE WHEN year = 'FR' THEN 'FR'
WHEN year = 'SO' THEN 'SO'
WHEN year = 'JR' THEN 'JR'
WHEN year = 'SR' THEN 'SR'
ELSE 'No Year Data' END AS year_group,
COUNT(1) AS count
FROM benn.college_football_players
GROUP BY 1
Can someone explain to me why this is working? In my understanding only aggregate functions are allowed in the SELECT clause (or functionally dependent columns - but there are no such columns in this case). However, the CASE statement clearly is not an aggregating function.