-
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
-
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
-
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
-
Forum Rules
|
|