Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAX(SUM(...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I would like to max the sum of a field:
I have:
"SELECT SUM(qnty),prod FROM tpurcd
GROUP BY prod"
-->this return the sums

but what i want is the max of these sums
like this:
"SELECT MAX(SUM(qnty)),prod,TO_CHAR(recv,'MM') FROM tpurcd
GROUP BY prod"
but error "not a single-group group function"

any ideas???

gawell
 

If you want to find the max SUM for a given set of date periods:

select MAX(z0.gross), z0.prod, z0.date
from
(select SUM(qnty) gross, prod, TO_CHAR( recv, 'MM') date
from tpurcd
group by prod, TO_CHAR( recv, 'MM') ) z0
group by z0.prod, z0.date ;
 
Your SQL:
"SELECT MAX(SUM(qnty)),prod,TO_CHAR(recv,'MM') FROM tpurcd
GROUP BY prod"
but error "not a single-group group function"

Should Read:
"SELECT MAX(SUM(qnty)),prod,TO_CHAR(recv,'MM') FROM tpurcd
GROUP BY prod, TO_CHAR(recv,'MM')"
 

Oracle 8i (do not know about 9i) does not allow nesting of aggregate functions so the correction to the SQL will still provide the same error.

 
Can you try something like the following....?

SELECT MAX(a.Max1) FROM
(SELECT MAX(SUM(qnty))AS MAX1
FROM
tpurcd
UNION
SELECT MAX(prod) AS MAX1
FROM
tpurcd) a
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top