Search code examples
sqlhaving

SQL query does not return anything with this HAVING clause


I want to have all Customer IDs which are higher than the average value of all IDs

SELECT k_vorname, k_nachname, k_ID FROM kunden GROUP BY k_ID HAVING k_ID > AVG(k_ID)

But this query returns nothing. Why?


Solution

  • You can try below

    SELECT k_vorname, k_nachname, k_ID FROM kunden 
    where k_id > (select AVG(k_ID) from kunden)