Query from the Aggregated Query with different projection

From: Sridharan <e_ssen_at_hotmail.com>
Date: 4 Jan 2004 06:10:30 -0800
Message-ID: <4afa61fa.0401040610.1466fa59_at_posting.google.com>


Hello All,

Below is how my data looks like

Branch Item Customer Sales

10    1    C1        300
10    1    C2        400
10    1    C3        200
10    2    C1        500
10    2    C3        300
10    3    C1        1200


With this Query

SELECT
    BRANCH,
    ITEM,
    COUNT(DISTINCT Customer || '-' || Branch) FROM
    TABLE1
GROUP BY
    BRANCH,
    ITEM
HAVING
    SUM(SALES) BETWEEN 1 AND 1000 The output will be

Branch Item CustomerCount
10 1 3
10 2 2

and

Item 3 will not come since the value is 1200.

Now I need the Distinct Customers who were part of that Query where the distinct Customer Count is only 3 and not the Sum (5). Now how do we get that value with the given query with all conditions applied.

Remember the SUM(SALES) should be applied to Branch And Item and from that I need the distinct CustomerCount.

Any help is highly appreciated. Received on Sun Jan 04 2004 - 15:10:30 CET

Original text of this message