Forum Moderators: coopster
I have been trying to find a resolution to this all over the web but nothing seems to fit my situation...
I have 1 table with fields. I am trying to setup a query where the result will GROUP by both fields... and be grouped in a separate column defined by an AS statement (group A,B AS xyz)
Example....
Table Name = dates_tbl
****************************
¦ date1 ¦ date 2 ¦
****************************
¦ Nov08 ¦ Dec08 ¦
¦ Jan08 ¦ Jan08 ¦
****************************
As you can see, I have Jan08 duplicated in 1 row...My query...
SELECT date1, date2
FROM dates_tbl
GROUP BY date1, date2 AS xyz....
The group by as is not possible...Does anybody know how to group multiple columns into 1 output? I hope im making sense....
THANKS!
select dtotal, sum(ctotal) as ftotal from
(select date1 as dtotal, count(*) as ctotal from date_tbl
group by dtotal
UNION ALL
select date2 as dtotal, count(*) as ctotal from date_tbl
group by dtotal)
as tmptable group by dtotal
Obviously, put a where clause in when necessary...dtotal will end up being the date, ftotal will be the number of times it exists in either column