| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Using DISTINCT AND SUM together SQL question
Mia <mmiaa_at_cox.net> wrote in message news:<3CB737B0.E737511D_at_cox.net>...
> Hi All,
>
> I've got a large table that I'm trying to write a query for. I don't
> fully understand the grouping functions, and I'm having some trouble
> getting what I want from the table. The table contains many columns but
> I am only interested in 3 of them. Call them ITEM, REV, and QTY. I
> (simply) want to do a SUM(QTY), but only for distinct rows of ITEM and
> REV.
>
> That is to say,
>
> SELECT DISTINCT ITEM, REV FROM ...
> and for that matter also
> SELECT DISTINCT ITEM, REV, QTY FROM ...
>
> both give me the rows I want. But how can I get SUM(QTY) for the whole
> set?
>
try
SELECT ITEM, REV, SUM(QTY) FROM (
SELECT DISTINCT ITEM, REV, QTY FROM ...
) AS A GROUP BY ITEM, REV
/Lennart
> TIA,
>
> Mia
Received on Sat Apr 13 2002 - 00:04:13 CDT
![]() |
![]() |