sql server - SQL Having aggregate function? -


i have table students , evaluations. necessary return number of repetitions ratings without min , max number of repetitions grade.

when i'am runnig query:

select       [grade],      count([grade]) [number of repetitions]      [test].[dbo].[evaluation]      group grade  

i have result , ok, how show query withuout min , max number of repetitions.(in case 6 - 120 , 10 - 4)

grade    number of repetitions  6              120  7              35  8              93  9              25 10              4  

i tried wtih having on way, not work. message in sql: "cannot perform aggregate function on expression containing aggregate or subquery"

select       [grade],      count([grade]) [number of repetitions]      [test].[dbo].[evaluation]      group grade       having count([grade) > (select min(count([grade])) [test][dbo].[evaluation] group grade)       ,       having count([grade) < (select max(count([grade])) [test][dbo].[evaluation] group grade) 

thank much.

you cannot nest aggregation functions that. there many approaches use solving this. in case, can extreme values using top , order by:

 having count([grade) > (select top 1 count([grade]) [test].[dbo].[evaluation] group grade order count([grade]) asc ) ,         count([grade) < (select top 1 count([grade]) [test].[dbo].[evaluation] group grade order count([grade]) desc) 

in addition, having keyword used once.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -