Skip to content
Advertisement

SELECT SUM as field

Suppose i have this table

table (a,b,c,d). Datatypes are not important.

I want to do this

…but I can’t find a way (sqldeveloper keeps complaining with “from clause not found”.)

Is there a way? Is it possible?

Advertisement

Answer

It’s much more simple and efficient to rewrite it as this:

Note the SUM(SUM(d)) here.

The innermost SUM is the aggregate function. It calculates the SUM(d) a-b-c-wise.

The outermost SUM is the analytic function. It sums the precalculated SUM(d)‘s a-b-wise, and returns the value along with each row.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement