Re: Aggregates on empty groups.

From: Marshall Spight <>
Date: Mon, 02 Aug 2004 16:02:34 GMT
Message-ID: <uAtPc.196165$a24.26266_at_attbi_s03>

"--CELKO--" <> wrote in message
> >> SELECT dept, SUM(sal) FROM Employees GROUP BY dept;
> .. and departments that are not in emp relation: Finance 0 <<
> But if Finance is not the Employees table, how does it get a group?
> You might build such a thing:
> SELECT dept, SUM(sal) FROM Employees GROUP BY dept
> SELECT DISTINCT dept, {NULL | 0.00} FROM OtherDepartments;
> or something with an OUTER JOIN, but this is not a simple GROUP BY.

(I'm renaming your "OtherDepartments" to "Departments", because I don't see anything "other" about it.)

ISTM that what you want is something like

for all dept in Departments, for all sal in Employees, (dept, sum(sal))

The closest thing is an outer join with a group by, I guess, but you have to IFNULL or some such, because SQL doesn't do folds on a zero length sequence right.

Marshall Received on Mon Aug 02 2004 - 18:02:34 CEST

Original text of this message