Hi, I can't get my head around this problem:
I have one table which records name, weekday and type of operation. I want to do a select query that returns every name and how many records there are for each name, and also how many of those are weekend/weekday and the count of each type.
Let's say I have the following table:
Then I want the following result:
So I have to do select on Name and count(*) for Total. I also have to filter on Type (0 = regular, 1 and 2 = special) and Date (Saturday and Sunday is weekend, all others have their own column).
I get in trouble when I do case-clause on Date and Type because I do not have them in group-by or aggreagate function. I tried with case-and sum but no such luck.
Any help would be much appreciated!
graabein
I have one table which records name, weekday and type of operation. I want to do a select query that returns every name and how many records there are for each name, and also how many of those are weekend/weekday and the count of each type.
Let's say I have the following table:
Code:
Name | Date | Type
A | 2006-05-01 | 0
A | 2006-04-30 | 1
A | 2006-05-02 | 2
Then I want the following result:
Code:
Name | Total | Regular | Special | Weekend | Mon | Tue...
A | 3 | 1 | 2 | 1 | 1 | 1
So I have to do select on Name and count(*) for Total. I also have to filter on Type (0 = regular, 1 and 2 = special) and Date (Saturday and Sunday is weekend, all others have their own column).
I get in trouble when I do case-clause on Date and Type because I do not have them in group-by or aggreagate function. I tried with case-and sum but no such luck.
Any help would be much appreciated!
graabein