How to calculate the average using conditions in SQL Server?

2

The question asks me to show the number of students with averages greater than 7, less than 7 or equal to 7 for some tables that I have here. Showing this way:

How to create this column of Description ?

    
asked by anonymous 01.09.2017 / 16:33

1 answer

6

AVG (Transact-SQL)

  

Returns the average of the values in a group. Null values are   ignored.

As you did not give details, I assume that your SQL will be something like:

SELECT CASE
   WHEN AVG(NOTA) > 7 THEN 'Superior a 7'
   WHEN AVG(NOTA) = 7 THEN 'Igual a 7'
   ELSE ' Inferior a 7'
   END 'Desrição',
   COUNT(*) Quantidade
FROM ALUNO
GROUP BY CLASSE
    
01.09.2017 / 16:45