sql - Week based count -


i have requirement retrieve data in below fashion

weeks  delay_count 0           6          1           0 2           3 3           4 4           0 5           1            6           0 7           0     8           0        9           0 10          2 11          0         12          0       13          0     14          0 15          3 

here weeks hard coded column 0 15 , delay_count derived column. have column delay_weeks. based on values in column need populate values in delay_count column (derived column)

delay_weeks column values below.

blank blank  blank  2 10 5 blank  3 2 10 2 3 3 3 0 0 15 22 29 

conditions:

  • when delay_weeks blank or 0 count in delay_count column should 1
  • when delay_weeks 3 in delay_count column count should 1 under week 3
  • when delay_weeks 10 in delay_count column count should 1 under week 10
  • when delay_weeks greater or equal 15 in delay_count column count should 1 under week 15.

i wrote code below

select   "weeks", a."delay_count"     (select     level "weeks"                 dual           connect level <= 15) m,          (select   value, count (value) "delay_numbers"               (select case                                           when attr11.value >= 15                                              '15'                                           else attr11.value                                        end                                      value                       docs,                            (select object_id, value, attribute_type_id                               attributes                              attribute_type_id =                                       (select attribute_type_id                                          attribute_types                                         name_display_code =                                                  'attribute_type.delay in weeks')) attr11                      docs.obj_id = attr11.object_id(+)            group value)    m."weeks" = a.value(+) 

select   weeks,   nvl(cnt, 0) delay_count   (select level-1 weeks dual connect level < 17)   left join (     select        nvl(least(attr11.value, 15), 0) weeks,       count(0) cnt            docs        left join (         attributes attr11          join attribute_types atr_tp using(attribute_type_id)       )          on atr_tp.name_display_code = 'attribute_type.delay in weeks'         , docs.obj_id = attr11.object_id     group nvl(least(attr11.value, 15), 0)   ) using(weeks) order 1 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -