Re: Aggregates in Queries
Posted in 1997
S SATHISH-SI a 'crit dans le message <622fhl$snt@cssun.mathcs.emory.edu>... >Hi, >Why does Online 7.1 disallow nesting aggregates in queries. >eg., >Select sum(max(sal)) from emp where ... group by ... >In case i want the sum of the maximum salaries in a department without >writing a subquery? You cannot reaggregate an aggregate, because the aggreate value is unique to each group, and reaggregating it has no sense other than returning the same value. If your intent is to evaluate the sum (for each employee) of maximum salaries (by department), so that you can evaluate the maximum salaries that each department could request (when reevaluating salaries) then you should group your request of employees by department, take the max of all salaries in that department, and multiply by the count of employees in each department: select max(sal) * count(*) from emp where... group by dept May be it is what you intended. It is legal to use several aggregates in the same selection column in your query. This allows you to compute further aggregates when those provied by the RDBMS do not meet your query. But all aggregates are computed on the same groups of rows. If it is not the case, you'll have to use subqueries to compute groups with different breaking level.