Previous Topic

Next Topic

Inhoudsopgave

Book Index

Nested Aggregates

ASE allows nested aggregates, MS SQL Server does not.

Example

create table Example (Id int, Amount int)

insert into Example values (1, 1)

insert into Example values (1, 10)

insert into Example values (2, 2)

insert into Example values (2, 20)

select Id, Sum(Amount) from Example group by Id

go

-- This statement will not work on MS SQL Server

select Id, Max(Sum(Amount)) from Example group by Id

go

drop table Example

Note: Although ASE seems to offer you more flexibility, the actual result of the query ‘select Id, Max(Sum(Amount)) from Example group by Id’ is somewhat unexpected. The maximum sum is evaluated correctly. However, this maximum is repeated for every record in the result set.