Why can't I perform an aggregate function on an expression containing an aggregate but I can do so by creating a new select statement around it?

后端 未结 7 715
囚心锁ツ
囚心锁ツ 2020-12-09 02:48

Why is it that in SQL Server I can\'t do this:

select  sum(count(id)) as \'count\'
from    table

But I can do

select sum(x.         


        
7条回答
  •  庸人自扰
    2020-12-09 03:36

    i would like to know what your expected result in this sql

    select  sum(count(id)) as 'count'
    from    table
    

    when you use the count function, only 1 result(total count) will be return. So, may i ask why you want to sum the only 1 result.

    You will surely got the error because an aggregate function cannot perform on an expression containing an aggregate or a subquery.

提交回复
热议问题