Is a "Group by" possible for column content?

2

I was wondering if it was possible to use GROUP BY based on the date of a column, in this case the ANALYSIS column that creates groups whenever it finds 0, instead of the column.

       DIA        MES       YEAR      TODAY   TOMORROW   ANALYSIS      LIMIT
---------- ---------- ---------- ---------- ---------- ---------- ----------
        19          9       2016        111        988          0        150 
        20          9       2016        988        853        853        150 
        21          9       2016        853        895        895        150 
        22          9       2016        895        776        776        150 
        23          9       2016        776        954          0        150 
        26          9       2016        954        968        968        150 
        27          9       2016        968        810        810        150 
        28          9       2016        810        937        937        150 
        29          9       2016        937        769        769        150 
        30          9       2016        769       1020          0        150 
         3         10       2016       1020        923        923        150 
         4         10       2016        923         32         32        150 

What you intended was the following, based on this example:

  • Group 1 (Analysis): 0
  • Group 2 (Analysis): 853, 895,776.0
  • Group 3 (Analysis): 968,810,937,169.0
  • ...
asked by anonymous 25.10.2017 / 00:30

1 answer

0

Using the "start-of-group" method, it is possible to do some sort of iterator.

select 
from   ( select tbl.*,
                count(case when analysis = 0 then 1 end) 
                           over (order by year, mes, dia) as cnt
         from   tbl
       )
where  ...
GROUP BY cnt;

This code was not made by me. so a big thank you to Mathguy .

    
25.10.2017 / 03:50