Re: Using DISTINCT AND SUM together SQL question
Date: 12 Apr 2002 22:04:13 -0700
Message-ID: <6dae7e65.0204122104.2d7cb7a_at_posting.google.com>
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 - 07:04:13 CEST
