Ken Puls
03-16-2006, 01:04 PM
I'm sure that this is an easy one, but I've tried with a Union query and a Left Join, and I keep getting an error telling me that there is a syntax error in my From clause... probably because there is. LOL!
SELECT CatagoryNames, Sum(CountOfCATEGORIES) as SUMOFCATS
FROM UNION ((SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_1 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_1) AS CountOfCATEGORIES
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_1 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_1),
(SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_2 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_2) AS CountOfCATEGORIES
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_2 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_2))
GROUP BY CatagoryNames
ORDER BY CatagoryNames;
I'm working with a vendor's DB which has a fairly poor setup, IMHO. There are about 24 catagories columns for each person. I need a total count of specific catagories, but I could have say "golf dues" in any one of those 24 catagory fields. I'm trying to build one summarized list of them.
I know that this does work:
SELECT CatagoryNames, Sum(CountOfCatagories) as SumOfCats
FROM (SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_1 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_1) AS CountOfCatagories
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_1 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_1)
GROUP BY CatagoryNames
ORDER BY CatagoryNames;
As does this:
SELECT CatagoryNames, Sum(CountOfCatagories) as SumOfCats
FROM (SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_2 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_2) AS CountOfCatagories
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_2 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_2)
GROUP BY CatagoryNames
ORDER BY CatagoryNames;
But how do I marry them together? As I say, there'll be 24 nested that I need in a master list.
I know that this should be simple, but my SQL is weak. :(
SELECT CatagoryNames, Sum(CountOfCATEGORIES) as SUMOFCATS
FROM UNION ((SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_1 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_1) AS CountOfCATEGORIES
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_1 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_1),
(SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_2 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_2) AS CountOfCATEGORIES
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_2 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_2))
GROUP BY CatagoryNames
ORDER BY CatagoryNames;
I'm working with a vendor's DB which has a fairly poor setup, IMHO. There are about 24 catagories columns for each person. I need a total count of specific catagories, but I could have say "golf dues" in any one of those 24 catagory fields. I'm trying to build one summarized list of them.
I know that this does work:
SELECT CatagoryNames, Sum(CountOfCatagories) as SumOfCats
FROM (SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_1 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_1) AS CountOfCatagories
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_1 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_1)
GROUP BY CatagoryNames
ORDER BY CatagoryNames;
As does this:
SELECT CatagoryNames, Sum(CountOfCatagories) as SumOfCats
FROM (SELECT [01_CLUB_MemberMaster].CATEGORY_LINE_2 AS CatagoryNames, Count([01_CLUB_MemberMaster].CATEGORY_LINE_2) AS CountOfCatagories
FROM 01_CLUB_MemberMaster GROUP BY [01_CLUB_MemberMaster].CATEGORY_LINE_2 ORDER BY [01_CLUB_MemberMaster].CATEGORY_LINE_2)
GROUP BY CatagoryNames
ORDER BY CatagoryNames;
But how do I marry them together? As I say, there'll be 24 nested that I need in a master list.
I know that this should be simple, but my SQL is weak. :(