Results 1 to 3 of 3

Thread: how to combine 2 sets of Group by ........

  1. #1
    Join Date
    Mar 2003
    Posts
    383

    how to combine 2 sets of Group by ........

    Hi:

    How can I combine 2 sets of group by together?

    same criteria on group by Region, county

    setA with where sum(timeSec) <= 30

    while setB with where sum(timeSec) > 30

    they are not necessary mutual exclusive. thus, union is not good.
    However, when I use derived table method, I will have 'dups' on column of 'Region' and 'county', 2 total are fine.

    thanks
    David

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    Something like this?

    SELECT setA.Region, setA.County, setA.SumTimeSecSetA, setB.SumTimeSecSetB
    FROM

    (SELECT Region, County, SUM(TimeSec) AS SumTimeSecSetA
    FROM YourTable
    GROUP BY Region, County
    HAVING SUM(TimeSec) <= 30) AS setA

    JOIN

    (SELECT Region, County, SUM(TimeSec) AS SumTimeSecSetB
    FROM YourTable
    GROUP BY Region, County
    HAVING SUM(TimeSec) > 30) AS setB

    ON setA.Region = setB.Region AND setA.County = setB.County

  3. #3
    Join Date
    Mar 2003
    Posts
    383
    Hi nosepicker:

    thanks for the tip.
    -D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •