I would appreciate if you guys could help me figure out how to: Select 12 separate counts on a single column based on time (for one date, I assume through a Declare Date first at the top and then insert time after, that part I think I understand) the second is once 12 separate cases are built run them 3 times so you would have 12 counts on 3 separate IDS.
All of this is in a single table.
the way I figure it would work but didn't is
Declare @Date DATE
set @Date = '24-11-2015'
Select (case(Select statement here) where Projectid in()) as A,
(case(Select statement here) where Projectid in()) as B,
(case(Select statement here) where Projectid in()) as C
If anyone understands what I mean, I would appreciate if you could help me out.
Input data:
Project id Datetime Necessary
---------- ----------------------- ---------
5 11-23-2015 09:00:00.000 1
5 11-23-2015 10:00:00.000 1
6 11-23-2015 11:00:00.000 0
1 11-23-2015 12:00:00.000 1
3 11-23-2015 13:00:00.000 1
124 11-23-2015 14:00:00.000 1
124 11-23-2015 15:00:00.000 1
124 11-23-2015 16:00:00.000 0
576 11-23-2015 17:00:00.000 0
576 11-23-2015 18:00:00.000 1
576 11-23-2015 19:00:00.000 1
etc 11-23-2015 20:00:00.000 1
Expected output:
Datetime 5 124 576
------------- --- --- ---
09:00 - 09:59 0 4 5
10:00 - 10:59 4 3 1
11:00 - 11:59 5 2 1
12:00 - 12:59 1 1 1
13:00 - 13:59 6 1 1
14:00 - 14:59 6 1 1
15:00 - 15:59 7 1 2
16:00 - 16:59 8 1 3
17:00 - 17:59 9 1 3
18:00 - 18:59 1 1 2
19:00 - 19:59 12 1 0
20:00 - 20:59 0 0 0
What I am looking for is projectids 5 124 and 576 as the column variables the way the rows should be counted is based on time per hour.
What I have so far with the help of Salman A
Hour 5 124 576
8 9 0 1
9 0 11 10
10 4 8 15
11 0 10 7
12 1 4 17
13 6 18 6
14 2 5 27
15 4 1 43
16 4 11 40
17 3 11 3
18 6 2 9
19 9 5 7