-
Notifications
You must be signed in to change notification settings - Fork 1
/
pmapp_reports.sql
1247 lines (1183 loc) · 56.8 KB
/
pmapp_reports.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
-- PMAPP REPORTS
*****************************************************************************/
-- **** base query: 1 row per (developer,project,day)
-- VERSION 2
-- Include overtime and lesstime
select * from pmapp.v_day_prj_dev;
create or replace view pmapp.v_day_prj_dev as
-- base query: 1 row per (developer,project,day)
with q1
as(
select date_key, project_id, developers_id, start_date, end_date, duration, free_of_charge_ind
from (
select a.developers_id,
a.prjs_id project_id,
--b.id project_id,
a.start_date, a.end_date, a.end_date - a.start_date duration, rpad('*', a.end_date-a.start_date,'*') pad,
free_of_charge_ind
from PMAPP.DEV_PRJS a --join pmapp.prjs b on(a.prjs_id = b.id)
where 1=1
--order by developers_id, start_date
) t1
--partition by (t1.developers_id, t1.prjs_id)
--right outer
join
(select date_key from target_dw.date_dim where working_day_ind = 1) t2
on(t2.date_key between trunc(t1.start_date) and trunc(t1.end_date))
order by date_key, project_id, developers_id, start_date
),
q2 -- overtime
as(
select *
from pmapp.dev_prjs
where
overtime_hrs is not null
or
lesstime_hrs is not null
)
select q1.date_key, q1.project_id, q1.developers_id, q1.start_date, q1.end_date, q1.duration, q1.free_of_charge_ind, q2.overtime_hrs, q2.lesstime_hrs
from q1 left join q2 on (q1.developers_id = q2.developers_id and q1.project_id = q2.prjs_id and q1.date_key = q2.start_date);
-- **** base query: 1 row per (developer,project,day)
-- VERSION 1
select * from pmapp.v_day_prj_dev;
create or replace view pmapp.v_day_prj_dev as
-- base query: 1 row per (developer,project,day)
select date_key, project_id, developers_id, start_date, end_date, duration, free_of_charge_ind
from (
select a.developers_id,
a.prjs_id project_id,
--b.id project_id,
a.start_date, a.end_date, a.end_date - a.start_date duration, rpad('*', a.end_date-a.start_date,'*') pad,
free_of_charge_ind
from PMAPP.DEV_PRJS a --join pmapp.prjs b on(a.prjs_id = b.id)
where 1=1
--order by developers_id, start_date
) t1
--partition by (t1.developers_id, t1.prjs_id)
--right outer
join
(select date_key from target_dw.date_dim where working_day_ind = 1) t2
on(t2.date_key between trunc(t1.start_date) and trunc(t1.end_date))
order by date_key, project_id, developers_id, start_date;
--**** DAYS PER DEVELOPER Per Month
-- VERSION 5
-- Add also mandays without overtime or lesstime. Also add overtime and lesstime in hours
-- Previous Version
-- Calculate mandays consumption by counting also unallocated working days and removing leaves. Also you must add overtime and
-- subtract lesstime. Also remove free of charge tasks
--
select * from pmapp.v_rep_mdays_per_dev_month;
create or replace view pmapp.v_rep_mdays_per_dev_month as
with wdays
as(
select date_key
from target_dw.date_dim
where working_day_ind = 1
and date_key between date'2015-03-26' and date'2020-03-26'
),
mdays_day_dev -- no leaves, based on task allocation
as (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
1 mdays_day_dev, --sum(mdays_prj_day_dev) mdays_day_dev ,
sum(nvl(overtime_days,0)) tot_overtime_days_weighted, sum(nvl(lesstime_days,0)) tot_lesstime_days
, sum(nvl(overtime_hrs,0)) tot_overtime_hrs, sum(nvl(lesstime_hrs,0)) tot_lesstime_hrs
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 * (1.5) overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t
where 1=1
AND project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
where 1=1
AND nvl(free_of_charge_ind, 0) <> 1 -- exclude free of charge tasks
group by developers_id, date_key, consumed_planned
),
leaves_and_foc --leaves and free of charge
as(
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects
-- , sum(mdays_prj_day_dev + nvl(overtime_days,0) - nvl(lesstime_days,0)) mdays_day_dev
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t
where
project_id = -2 -- include leaves
or (
-- include free of charge tasks ONLY IF there is no other chargable task in the same day for the same developer
nvl(free_of_charge_ind, 0) = 1
AND NOT EXISTS (select 1 from pmapp.v_day_prj_dev where date_key = t.date_key and developers_id = t.developers_id and nvl(free_of_charge_ind, 0) = 0)
)
--or nvl(free_of_charge_ind, 0) = 1 -- include free of charge tasks
order by developers_id, date_key, project_id, start_date
)
where 1=1
group by developers_id, date_key, consumed_planned
),
mdays_day_dev_final
as(
select t1.developers_id,
t2.date_key,
t1.consumed_planned,
t1.projects ,
t1.mdays_day_dev, t1.tot_overtime_days_weighted, t1.tot_lesstime_days, t1.tot_overtime_hrs, t1.tot_lesstime_hrs
from
mdays_day_dev t1
partition by (t1.developers_id)
right outer join
wdays t2 --wdays_no_leaves_and_foc t2
on (t1.date_key = t2.date_key)
),
md_day_dev_fin_no_leaves_foc
as(
select *
from mdays_day_dev_final
where
(developers_id, date_key) not in (select developers_id, date_key from leaves_and_foc)
order by developers_id, date_key
)
select to_char(date_key, 'YYYY/MM') month, --trunc(date_key, 'MM') month, --
t2.name dev_name, nvl(t1.consumed_planned, 'UNALLOCATED') consumed_planned,
round(sum(nvl(mdays_day_dev,1)),1) mandays, nvl(round(sum(tot_overtime_days_weighted),1),0) overtime_days, nvl(round(sum(tot_lesstime_days),1),0) lesstime_days
,nvl(round(sum(tot_overtime_hrs),1),0) overtime_hrs, nvl(round(sum(tot_lesstime_hrs),1),0) lesstime_hrs
from md_day_dev_fin_no_leaves_foc t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
--AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave (extra filter on leaves: This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point gaurantees that we exclude all days with leaves)
group by to_char(date_key, 'YYYY/MM'), --trunc(date_key, 'MM'),
t2.name, t1.consumed_planned
order by month, dev_name, consumed_planned;
--**** DAYS PER DEVELOPER Per Month
-- VERSION 4
-- Calculate mandays consumption by counting also unallocated working days and removing leaves. Also you must add overtime and
-- subtract lesstime. Also remove free of charge tasks
--
select * from pmapp.v_rep_mdays_per_dev_month;
create or replace view pmapp.v_rep_mdays_per_dev_month as
with wdays
as(
select date_key
from target_dw.date_dim
where working_day_ind = 1
and date_key between date'2015-03-26' and date'2016-03-26'
),
mdays_day_dev -- no leaves, based on task allocation
as (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
1 mdays_day_dev, --sum(mdays_prj_day_dev) mdays_day_dev ,
sum(nvl(overtime_days,0)) overtime, sum(nvl(lesstime_days,0)) lesstime
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 * (1.5) overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t
where 1=1
AND project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
where 1=1
AND nvl(free_of_charge_ind, 0) <> 1 -- exclude free of charge tasks
group by developers_id, date_key, consumed_planned
),
leaves_and_foc --leaves and free of charge
as(
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
sum(mdays_prj_day_dev + nvl(overtime_days,0) - nvl(lesstime_days,0)) mdays_day_dev
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t
where
project_id = -2 -- include leaves
or (
-- include free of charge tasks ONLY IF there is no other chargable task in the same day for the same developer
nvl(free_of_charge_ind, 0) = 1
AND NOT EXISTS (select 1 from pmapp.v_day_prj_dev where date_key = t.date_key and developers_id = t.developers_id and nvl(free_of_charge_ind, 0) = 0)
)
--or nvl(free_of_charge_ind, 0) = 1 -- include free of charge tasks
order by developers_id, date_key, project_id, start_date
)
where 1=1
group by developers_id, date_key, consumed_planned
),
mdays_day_dev_final
as(
select t1.developers_id,
t2.date_key,
t1.consumed_planned,
t1.projects ,
t1.mdays_day_dev, t1.overtime, t1.lesstime
from
mdays_day_dev t1
partition by (t1.developers_id)
right outer join
wdays t2 --wdays_no_leaves_and_foc t2
on (t1.date_key = t2.date_key)
),
md_day_dev_fin_no_leaves_foc
as(
select *
from mdays_day_dev_final
where
(developers_id, date_key) not in (select developers_id, date_key from leaves_and_foc)
order by developers_id, date_key
)
select to_char(date_key, 'YYYY/MM') month, --trunc(date_key, 'MM') month, --
t2.name dev_name, nvl(t1.consumed_planned, 'UNALLOCATED') consumed_planned,
round(sum(nvl(mdays_day_dev,1)),1) mandays, nvl(round(sum(overtime),1),0) overtime_days, nvl(round(sum(lesstime),1),0) lesstime_days
from md_day_dev_fin_no_leaves_foc t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
--AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave (extra filter on leaves: This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point gaurantees that we exclude all days with leaves)
group by to_char(date_key, 'YYYY/MM'), --trunc(date_key, 'MM'),
t2.name, t1.consumed_planned
order by month, dev_name, consumed_planned;
--**** DAYS PER DEVELOPER Per Month
-- VERSION 3
-- added overtime and lesstime mandays with a more elegant way (compared to version 2)
select * from pmapp.v_rep_mdays_per_dev_month;
create or replace view pmapp.v_rep_mdays_per_dev_month as
select to_char(date_key, 'MM/YYYY') month, nvl(t2.name,'TOTAL') dev_name, nvl(t1.consumed_planned, 'TOTAL') consumed_planned,
round(sum(mdays_day_dev),1) mandays--,
--count(t1.date_key) mandays_old,
--round(count(t1.date_key)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else count(t1.date_key) end) over()*100,1) pct_old,
--round(round(sum(mdays_day_dev),1)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else round(sum(mdays_day_dev),1) end) over()*100,1) pct
from (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
sum(mdays_prj_day_dev + nvl(overtime_days,0) - nvl(lesstime_days,0)) mdays_day_dev
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t
where 1=1
AND project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
where 1=1
AND nvl(free_of_charge_ind, 0) <> 1 -- exclude free of charge tasks
group by developers_id, date_key, consumed_planned
) t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave (extra filter on leaves: This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point gaurantees that we exclude all days with leaves)
group by to_char(date_key, 'MM/YYYY'), t2.name, t1.consumed_planned
order by month, dev_name, consumed_planned ;
--**** DAYS PER DEVELOPER Per Month
-- VERSION 2 : includes overtime and lesstime
select * from pmapp.v_rep_mdays_per_dev_month;
create or replace view pmapp.v_rep_mdays_per_dev_month as
select to_char(date_key, 'MM/YYYY') month, nvl(t2.name,'TOTAL') dev_name, nvl(t1.consumed_planned, 'TOTAL') consumed_planned,
round(sum(mdays_day_dev),1) mandays--,
--count(t1.date_key) mandays_old,
--round(count(t1.date_key)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else count(t1.date_key) end) over()*100,1) pct_old,
--round(round(sum(mdays_day_dev),1)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else round(sum(mdays_day_dev),1) end) over()*100,1) pct
from (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
sum(mdays_prj_day_dev) mdays_day_dev
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev
from pmapp.v_day_prj_dev t
where 1=1
AND project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
where 1=1
AND nvl(free_of_charge_ind, 0) <> 1 -- exclude free of charge tasks
group by developers_id, date_key, consumed_planned
union all
-- developers overtime
select developers_id,
start_date date_key,
case when start_date < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
to_char(prjs_id) projects ,
(nvl(overtime_hrs,0) - nvl(lesstime_hrs,0))/8 mdays_day_dev
from pmapp.dev_prjs
where 1=1
AND prjs_id <> -2 -- exclude leaves
) t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave (extra filter on leaves: This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point it is not gauranteed to exclude all days with leaves)
group by to_char(date_key, 'MM/YYYY'), t2.name, t1.consumed_planned
order by month, dev_name, consumed_planned ;
--**** DAYS PER DEVELOPER Per Month
-- VERSION 1
select * from pmapp.v_rep_mdays_per_dev_month;
create or replace view pmapp.v_rep_mdays_per_dev_month as
select to_char(date_key, 'MM/YYYY') month, nvl(t2.name,'TOTAL') dev_name, nvl(t1.consumed_planned, 'TOTAL') consumed_planned,
round(sum(mdays_day_dev),1) mandays--,
--count(t1.date_key) mandays_old,
--round(count(t1.date_key)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else count(t1.date_key) end) over()*100,1) pct_old,
--round(round(sum(mdays_day_dev),1)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else round(sum(mdays_day_dev),1) end) over()*100,1) pct
from (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
sum(mdays_prj_day_dev) mdays_day_dev
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev
from pmapp.v_day_prj_dev t
where 1=1
AND project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
where 1=1
AND nvl(free_of_charge_ind, 0) <> 1 -- exclude free of charge tasks
group by developers_id, date_key, consumed_planned
) t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave (extra filter on leaves: This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point it is not gauranteed to exclude all days with leaves)
group by to_char(date_key, 'MM/YYYY'), t2.name, t1.consumed_planned
order by month, dev_name, consumed_planned ;
-- **** DAYS PER DEVELOPER (i.e., up to sysdate, including today) (excluding leaves, operational support)
-- VERSION 2
-- Make more precise calculation of the consumed manday. Allow a calculation of the type 1/num_of_projects for each
-- assignement within the day
select * from pmapp.v_rep_mdays_per_dev;
create or replace view pmapp.v_rep_mdays_per_dev
as
select nvl(t2.name,'TOTAL') dev_name, nvl(t1.consumed_planned, 'TOTAL') consumed_planned,
round(sum(mdays_day_dev),1) mandays,
--count(t1.date_key) mandays_old,
--round(count(t1.date_key)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else count(t1.date_key) end) over()*100,1) pct_old,
round(round(sum(mdays_day_dev),1)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else round(sum(mdays_day_dev),1) end) over()*100,1) pct
from (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects ,
sum(mdays_prj_day_dev) mdays_day_dev
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev
from pmapp.v_day_prj_dev t
where 1=1
AND project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
where 1=1
AND nvl(free_of_charge_ind, 0) <> 1 -- exclude free of charge tasks
group by developers_id, date_key, consumed_planned
) t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave (extra filter on leaves: This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point it is not gauranteed to exclude all days with leaves)
group by rollup(t2.name, t1.consumed_planned)
order by dev_name, consumed_planned ;
-- **** DAYS PER DEVELOPER (i.e., up to sysdate, including today) (excluding leaves, operational support)
-- VERSION 1
select * from pmapp.v_rep_mdays_per_dev;
create or replace view pmapp.v_rep_mdays_per_dev
as
select nvl(t2.name,'TOTAL') dev_name, nvl(t1.consumed_planned, 'TOTAL') consumed_planned, count(t1.date_key) mandays, round(count(t1.date_key)/sum(case when (t2.name IS NULL OR t1.consumed_planned IS NULL) then 0 else count(t1.date_key) end) over()*100,1) pct
from (
-- 1 row per day, developer
select developers_id,
date_key,
consumed_planned,
listagg(project_id, ',') WITHIN GROUP (ORDER BY start_date ) projects --,
--listagg(pm, ',') WITHIN GROUP (ORDER BY start_date, pm) pms,
--count(distinct project_id) num_projects
from (
-- base query: 1 row per (developer,project,day)
select t.*,
case when DATE_KEY <= SYSDATE + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned
from pmapp.v_day_prj_dev t
where 1=1
--AND project_id <> -2 -- exclude leaves (Comment out this filter because I will put it after list_agg aggregation. This due to the fact that sometimes project assignments appear in the same day with a leave (-2). So the filter at this point it is not gauranteed to exclude all days with leaves)
AND project_id <> -1 -- exclude operational support
AND project_id <> 0 -- exclude generic task
AND nvl(t.free_of_charge_ind, 0) <> 1
--AND DATE_KEY <= SYSDATE + 1
order by developers_id, date_key, project_id, start_date
)
group by developers_id, date_key, consumed_planned
) t1
join developers t2 on(t1.developers_id = t2.id)
where 1=1
AND instr(t1.projects, '-2') = 0 -- exclude days that contain a leave
group by rollup(t2.name, t1.consumed_planned)
order by dev_name, consumed_planned ;
-- **** MANDAYS PER CR
--
-- VERSION 5
-- add OP 2016 projects
-- add go live date
-- Óôï APEX query Ýâáëá êáé "'PLANNED - BUDGETARY" êáôçãïñßá
--
-- VERSION 4
-- add project population date
--
-- VERSION 3
-- added overtime and lesstime mandays
--
-- VERSION 2
-- Include also Operational Support in the calculation. I.e., if a developer in a day has Op Support then this must count
-- in the denominator of the manday allocation i.e., 1/num_of_projs_within_day. Then Operational Support can be filtered out
-- from the final list of projects (since is not a CR).
-- Also, the free_of_charge projects must also be counted in this denominator and be filtered later on from the list.
-- Also, correct calculation for CONSUMED/PLANNED from DATE_KEY <= SYSDATE + 1 to DATE_KEY < trunc(SYSDATE) + 1
--
-- Notes:
-- Mandays are NOT "Elapsed Days", so we have to calculate the percentage of the day allocated to a CR
-- so as not to double count the days
-- USE a "CONSUMED_PLAN" column so as not to have to use 2 separate views to show consumed vs. plannes mandays
-- APEX query
select rownum r, t.*
from (
select "BUSINESS_UNIT",
upper("OPERATING_PLAN_ID") OPERATING_PLAN_ID,
"OP",
"BUGZILLA_ID",
"NAME_DESCRIPTION",
"PROJECT_ID",
"DEPT",
"PM",
"STATUS",
"START_OF_UAT",
"GO_LIVE_DATE",
"COMPLETION_DATE",
"MDAYS_PRJ",
"CONSUMED_PLANNED",
"COMPANY",
'Time and Material' PTYPE,
population_date
from v_rep_mdays_per_cr
union all
select /* Fixed Price Projects from Q1 2015 */
business_unit,
upper(operating_plan_id) OPERATING_PLAN_ID,
case when operating_plan_id IS NULL then 'NOT IN OP'
when operating_plan_id like '%2016%' then 'IN OP 2016'
when operating_plan_id like '%2015%' then 'IN OP 2015'
else 'IN OP (not 2015,2016)' end OP,
bugzilla_id,
name_description,
null project_id,
null dept,
pm,
'COMPLETED' status,
null start_of_uat,
null go_live_date,
date'2015-03-31' completion_date,
to_number(mdays) MDAYS_PRJ,
'CONSUMED' CONSUMED_PLANNED,
COMPANY,
'Fixed Price' PTYPE,
to_date('31/03/3015','dd/mm/yyyy') population_date
from fixed_price_prjs_from_xls
union all
select "BUSINESS_UNIT",
upper("OPERATING_PLAN_ID") OPERATING_PLAN_ID,
case when operating_plan_id IS NULL then 'NOT IN OP'
when operating_plan_id like '%2016%' then 'IN OP 2016'
when operating_plan_id like '%2015%' then 'IN OP 2015'
else 'IN OP (not 2015,2016)' end OP,
"BUGZILLA_ID",
"NAME_DESCRIPTION",
id "PROJECT_ID",
"DEPT",
"PM",
"STATUS",
"START_OF_UAT",
"GO_LIVE_DATE",
"COMPLETION_DATE",
"MAN_DAYS",
'PLANNED - BUDGETARY' "CONSUMED_PLANNED",
null "COMPANY",
'Time and Material' PTYPE,
population_date
from pmapp.prjs
where
status in ('NOT STARTED - NOT PLANNED', 'NOT STARTED - PLANNED')
and man_days IS NOT NULL
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned
) t;
select * from fixed_price_prjs_from_xls;
select rownum r, t.* from v_rep_mdays_per_cr t;
create or replace view v_rep_mdays_per_cr as
select business_unit,
operating_plan_id, case when operating_plan_id IS NULL then 'NOT IN OP'
when operating_plan_id like '%2016%' then 'IN OP 2016'
when operating_plan_id like '%2015%' then 'IN OP 2015'
else 'IN OP (not 2015,2016)' end OP,
bugzilla_id, name_description, project_id, dept, pm, status, start_of_uat, go_live_date, completion_date, population_date,
round(sum(mdays_prj_day),1) mdays_prj, consumed_planned, company
from (
-- 1 row per day, project
select s3.business_unit,
s3.operating_plan_id,
s1.project_id,
s3.bugzilla_id,
s1.date_key,
s3.name_description,
s3.dept,
s3.pm,
--s3.prj_type,
s3.status,
s3.start_of_uat,
s3.go_live_date,
s3.completion_date,
s3.population_date,
--sum(mdays_prj_day_dev) mdays_prj_day,
sum(mdays_prj_day_dev + nvl(overtime_days,0) - nvl(lesstime_days,0)) mdays_prj_day,
s1.consumed_planned,
s2.company
from (
-- base query: 1 row per (developer,project,day)
select t1.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t1
where 1=1
AND t1.project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by project_id, date_key, developers_id, start_date
) s1
join developers s2 on(s1.developers_id = s2.id)
join prjs s3 on (s1.project_id = s3.id)
where 1=1
AND nvl(s1.free_of_charge_ind,0) <> 1 -- exclude free of charge
AND s3.prj_type = 'Change Request'
--AND s3.dept <> 'MDW'
group by s1.project_id, s3.bugzilla_id, s1.date_key, s3.business_unit, s3.operating_plan_id, s3.name_description, s3.dept, s3.pm, s3.status,
s3.start_of_uat, s3.go_live_date,
s3.completion_date, s3.population_date, s2.company, s1.consumed_planned
order by business_unit, project_id, date_key, company
) p1
where 1=1
group by project_id, name_description, bugzilla_id, dept, pm, status, start_of_uat, go_live_date,
completion_date, population_date, business_unit, operating_plan_id, company, consumed_planned,
case when operating_plan_id IS NULL then 'NOT IN OP'
when operating_plan_id like '%2016%' then 'IN OP 2016'
when operating_plan_id like '%2015%' then 'IN OP 2015'
else 'IN OP (not 2015,2016)' end
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned;
-- **** MANDAYS PER CR
-- VERSION 4
-- add project population date
--
-- VERSION 3
-- added overtime and lesstime mandays
--
-- VERSION 2
-- Include also Operational Support in the calculation. I.e., if a developer in a day has Op Support then this must count
-- in the denominator of the manday allocation i.e., 1/num_of_projs_within_day. Then Operational Support can be filtered out
-- from the final list of projects (since is not a CR).
-- Also, the free_of_charge projects must also be counted in this denominator and be filtered later on from the list.
-- Also, correct calculation for CONSUMED/PLANNED from DATE_KEY <= SYSDATE + 1 to DATE_KEY < trunc(SYSDATE) + 1
--
-- Notes:
-- Mandays are NOT "Elapsed Days", so we have to calculate the percentage of the day allocated to a CR
-- so as not to double count the days
-- USE a "CONSUMED_PLAN" column so as not to have to use 2 separate views to show consumed vs. plannes mandays
select rownum r, t.*
from (
select "BUSINESS_UNIT",
upper("OPERATING_PLAN_ID") OPERATING_PLAN_ID,
"OP",
"BUGZILLA_ID",
"NAME_DESCRIPTION",
"PROJECT_ID",
"DEPT",
"PM",
"STATUS",
"START_OF_UAT",
"COMPLETION_DATE",
"MDAYS_PRJ",
"CONSUMED_PLANNED",
"COMPANY",
'Time and Material' PTYPE,
population_date
from v_rep_mdays_per_cr
union all
select /* Fixed Price Projects from Q1 2015 */
business_unit,
upper(operating_plan_id) OPERATING_PLAN_ID,
case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end OP,
bugzilla_id,
name_description,
null project_id,
null dept,
pm,
'COMPLETED' status,
null start_of_uat,
date'2015-03-31' completion_date,
to_number(mdays) MDAYS_PRJ,
'CONSUMED' CONSUMED_PLANNED,
COMPANY,
'Fixed Price' PTYPE,
to_date('31/03/3015','dd/mm/yyyy') population_date
from fixed_price_prjs_from_xls
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned
) t;
select * from fixed_price_prjs_from_xls;
select rownum r, t.* from v_rep_mdays_per_cr t;
create or replace view v_rep_mdays_per_cr as
select business_unit,
operating_plan_id, case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end OP,
bugzilla_id, name_description, project_id, dept, pm, status, start_of_uat, completion_date, population_date,
round(sum(mdays_prj_day),1) mdays_prj, consumed_planned, company
from (
-- 1 row per day, project
select s3.business_unit,
s3.operating_plan_id,
s1.project_id,
s3.bugzilla_id,
s1.date_key,
s3.name_description,
s3.dept,
s3.pm,
--s3.prj_type,
s3.status,
s3.start_of_uat,
s3.completion_date,
s3.population_date,
--sum(mdays_prj_day_dev) mdays_prj_day,
sum(mdays_prj_day_dev + nvl(overtime_days,0) - nvl(lesstime_days,0)) mdays_prj_day,
s1.consumed_planned,
s2.company
from (
-- base query: 1 row per (developer,project,day)
select t1.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t1
where 1=1
AND t1.project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by project_id, date_key, developers_id, start_date
) s1
join developers s2 on(s1.developers_id = s2.id)
join prjs s3 on (s1.project_id = s3.id)
where 1=1
AND nvl(s1.free_of_charge_ind,0) <> 1 -- exclude free of charge
AND s3.prj_type = 'Change Request'
--AND s3.dept <> 'MDW'
group by s1.project_id, s3.bugzilla_id, s1.date_key, s3.business_unit, s3.operating_plan_id, s3.name_description, s3.dept, s3.pm, s3.status, s3.start_of_uat,
s3.completion_date, s3.population_date, s2.company, s1.consumed_planned
order by business_unit, project_id, date_key, company
) p1
where 1=1
group by project_id, name_description, bugzilla_id, dept, pm, status, start_of_uat,
completion_date, population_date, business_unit, operating_plan_id, company, consumed_planned,
case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned;
-- **** MANDAYS PER CR
-- VERSION 3
-- added overtime and lesstime mandays
--
-- VERSION 2
-- Include also Operational Support in the calculation. I.e., if a developer in a day has Op Support then this must count
-- in the denominator of the manday allocation i.e., 1/num_of_projs_within_day. Then Operational Support can be filtered out
-- from the final list of projects (since is not a CR).
-- Also, the free_of_charge projects must also be counted in this denominator and be filtered later on from the list.
-- Also, correct calculation for CONSUMED/PLANNED from DATE_KEY <= SYSDATE + 1 to DATE_KEY < trunc(SYSDATE) + 1
--
-- Notes:
-- Mandays are NOT "Elapsed Days", so we have to calculate the percentage of the day allocated to a CR
-- so as not to double count the days
-- USE a "CONSUMED_PLAN" column so as not to have to use 2 separate views to show consumed vs. plannes mandays
select rownum r, t.*
from (
select "BUSINESS_UNIT",
upper("OPERATING_PLAN_ID") OPERATING_PLAN_ID,
"OP",
"BUGZILLA_ID",
"NAME_DESCRIPTION",
"PROJECT_ID",
"DEPT",
"PM",
"STATUS",
"START_OF_UAT",
"COMPLETION_DATE",
"MDAYS_PRJ",
"CONSUMED_PLANNED",
"COMPANY",
'Time and Material' PTYPE
from v_rep_mdays_per_cr
union all
select /* Fixed Price Projects from Q1 2015 */
business_unit,
upper(operating_plan_id) OPERATING_PLAN_ID,
case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end OP,
bugzilla_id,
name_description,
null project_id,
null dept,
pm,
'COMPLETED' status,
null start_of_uat,
date'2015-03-31' completion_date,
to_number(mdays) MDAYS_PRJ,
'CONSUMED' CONSUMED_PLANNED,
COMPANY,
'Fixed Price' PTYPE
from fixed_price_prjs_from_xls
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned
) t;
select * from fixed_price_prjs_from_xls;
select rownum r, t.* from v_rep_mdays_per_cr t;
create or replace view v_rep_mdays_per_cr as
select business_unit,
operating_plan_id, case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end OP,
bugzilla_id, name_description, project_id, dept, pm, status, start_of_uat, completion_date,
round(sum(mdays_prj_day),1) mdays_prj, consumed_planned, company
from (
-- 1 row per day, project
select s3.business_unit,
s3.operating_plan_id,
s1.project_id,
s3.bugzilla_id,
s1.date_key,
s3.name_description,
s3.dept,
s3.pm,
--s3.prj_type,
s3.status,
s3.start_of_uat,
s3.completion_date,
--sum(mdays_prj_day_dev) mdays_prj_day,
sum(mdays_prj_day_dev + nvl(overtime_days,0) - nvl(lesstime_days,0)) mdays_prj_day,
s1.consumed_planned,
s2.company
from (
-- base query: 1 row per (developer,project,day)
select t1.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev,
overtime_hrs/8 overtime_days, lesstime_hrs/8 lesstime_days
from pmapp.v_day_prj_dev t1
where 1=1
AND t1.project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by project_id, date_key, developers_id, start_date
) s1
join developers s2 on(s1.developers_id = s2.id)
join prjs s3 on (s1.project_id = s3.id)
where 1=1
AND nvl(s1.free_of_charge_ind,0) <> 1 -- exclude free of charge
AND s3.prj_type = 'Change Request'
--AND s3.dept <> 'MDW'
group by s1.project_id, s3.bugzilla_id, s1.date_key, s3.business_unit, s3.operating_plan_id, s3.name_description, s3.dept, s3.pm, s3.status, s3.start_of_uat,
s3.completion_date, s2.company, s1.consumed_planned
order by business_unit, project_id, date_key, company
) p1
where 1=1
group by project_id, name_description, bugzilla_id, dept, pm, status, start_of_uat,
completion_date, business_unit, operating_plan_id, company, consumed_planned,
case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned;
-- **** MANDAYS PER CR
-- VERSION 2
-- Include also Operational Support in the calculation. I.e., if a developer in a day has Op Support then this must count
-- in the denominator of the manday allocation i.e., 1/num_of_projs_within_day. Then Operational Support can be filtered out
-- from the final list of projects (since is not a CR).
-- Also, the free_of_charge projects must also be counted in this denominator and be filtered later on from the list.
-- Also, correct calculation for CONSUMED/PLANNED from DATE_KEY <= SYSDATE + 1 to DATE_KEY < trunc(SYSDATE) + 1
--
-- Notes:
-- Mandays are NOT "Elapsed Days", so we have to calculate the percentage of the day allocated to a CR
-- so as not to double count the days
-- USE a "CONSUMED_PLAN" column so as not to have to use 2 separate views to show consumed vs. plannes mandays
select rownum r, t.*
from (
select "BUSINESS_UNIT",
upper("OPERATING_PLAN_ID") OPERATING_PLAN_ID,
"OP",
"BUGZILLA_ID",
"NAME_DESCRIPTION",
"PROJECT_ID",
"DEPT",
"PM",
"STATUS",
"START_OF_UAT",
"COMPLETION_DATE",
"MDAYS_PRJ",
"CONSUMED_PLANNED",
"COMPANY",
'Time and Material' PTYPE
from v_rep_mdays_per_cr
union all
select /* Fixed Price Projects from Q1 2015 */
business_unit,
upper(operating_plan_id) OPERATING_PLAN_ID,
case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end OP,
bugzilla_id,
name_description,
null project_id,
null dept,
pm,
'COMPLETED' status,
null start_of_uat,
date'2015-03-31' completion_date,
to_number(mdays) MDAYS_PRJ,
'CONSUMED' CONSUMED_PLANNED,
'UNISYSTEMS' COMPANY,
'Fixed Price' PTYPE
from fixed_price_prjs_from_xls
order by business_unit, bugzilla_id, project_id desc, name_description, status, company, consumed_planned
) t;
select * from fixed_price_prjs_from_xls;
select rownum r, t.* from v_rep_mdays_per_cr t;
create or replace view v_rep_mdays_per_cr as
select business_unit,
operating_plan_id, case when operating_plan_id IS NULL then 'NOT IN OP' when operating_plan_id like '%2015%' then 'IN OP 2015' else 'IN OP (not 2015)' end OP,
bugzilla_id, name_description, project_id, dept, pm, status, start_of_uat, completion_date,
round(sum(mdays_prj_day),1) mdays_prj, consumed_planned, company
from (
-- 1 row per day, project
select s3.business_unit,
s3.operating_plan_id,
s1.project_id,
s3.bugzilla_id,
s1.date_key,
s3.name_description,
s3.dept,
s3.pm,
--s3.prj_type,
s3.status,
s3.start_of_uat,
s3.completion_date,
sum(mdays_prj_day_dev) mdays_prj_day,
s1.consumed_planned,
s2.company
from (
-- base query: 1 row per (developer,project,day)
select t1.*,
case when DATE_KEY < trunc(SYSDATE) + 1 then 'CONSUMED' ELSE 'PLANNED' end consumed_planned,
round(1/count(project_id) over(partition by date_key, developers_id),2) mdays_prj_day_dev
from pmapp.v_day_prj_dev t1
where 1=1
AND t1.project_id <> -2 -- exclude leaves
--AND project_id <> -1 -- exclude operational support
--AND project_id <> 0 -- exclude generic task
--AND DATE_KEY <= SYSDATE + 1
order by project_id, date_key, developers_id, start_date
) s1
join developers s2 on(s1.developers_id = s2.id)
join prjs s3 on (s1.project_id = s3.id)
where 1=1
AND nvl(s1.free_of_charge_ind,0) <> 1 -- exclude free of charge
AND s3.prj_type = 'Change Request'