Counties of simple order of magnitude... do exist?

Normally I don't deal with SQL, so apologies if I'm asking is dumb / obvious.

I have a [orders] table with about 300 000 000 lines. It is quite large (approx. 500 b on avg).

There is a unique index [idx_a] on [order_id, order_dt, store_chain, store_id]
There is another index [idx_b] on [order_dt,.. .several other columns...]

At a high level, I want to do something like:

SELECT TO_CHAR (order_dt, "YYYY"), COUNT (*)
Orders
GROUP BY order_dt

But I'm not really interested in the exact number, I'm more interested in an order of magnitude summary. The system is online and direct and has constantly arrested since the different points of sale (about 20 per minute). I tried in an environment of running the above query test, but he does not terminate within 15 minutes.

Is there a smarter way to do this?

Howler_Fish wrote:
At a high level, I want to do something like:

SELECT TO_CHAR (order_dt, "YYYY"), COUNT (*)
Orders
GROUP BY order_dt

But I'm not really interested in the exact number, I'm more interested in an order of magnitude summary. The system is online and direct and has constantly arrested since the different points of sale (about 20 per minute). I tried in an environment of running the above query test, but he does not terminate within 15 minutes.

Is there a smarter way to do this?

Apart from the other advice you have already, you can try to use "sampling" If you are really interesting just a "rough": estimate

SELECT TO_CHAR (order_dt, "YYYY"), COUNT ()) * 10, according to the NTC
Examples of controls (10)
GROUP BY order_dt;

That would be "sample" only 10% of the lines by using the clause of "SAMPLE", so you have to multiply the number by the same factor to get comparable to the 'real' query results

Please note that depending on how "asymmetric" distribution of your data is in any of the blocks table if you use only a small sample your results, maybe average, then you might need to test with varying degrees of sampling.

Kind regards
Randolf

Oracle related blog stuff:
http://Oracle-Randolf.blogspot.com/

SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/

Tags: Database

Similar Questions

  • Digital control over several orders of magnitude

    Hi all,

    I'm trying to get a digital control with a suitable addition to the order of magnitude.

    For example, I have a front panel for an osziloscope, sometimes that samples on some ns, sometimes a few seconds, sometimes a few milivolts, sometimes a few volts, who knows, right
    I was playing around with the digital control units, but it doesn't quite fit my needs. I can't change the prefix of a unit on the duration, for example of microseconds to seconds, but then I change the issue as well, because on change the prefix, the previous number is only multiplied by the factor according to, for example, 1000, so 5 became US 5th-6s. So change the record length of the default value of 500 ms to 100 ns would require two klicks type, and I can instead just type "100th-9', which is good too."

    However, I would like to have a digital control from 0 to 1000 combined with for example a button for prefix i.e. nano, micro, mili etc. and combine this values internally, i.e. of mulitplying accordingly. But I couldn't set the increment to "3 orders of magnitude" even with the option to log scale.

    I know, I could use an enum with the names and values according to, but this is not very satisfactory.

    So perhaps the question would be: is it possible to combine two digital controls or the value for the prefix, in a suitable and easy way? Or how do you manage the digital values over several orders of magnitude in a case like mine?

    Thanks for your replies in advance.

    Best,

    bastlwastl

    Display format is SI units

    It helps in these situations

  • How can I get my card to bracts newspaper to zoom to get closer to an order of magnitude?

    I have data may vary over several orders of magnitude and sometimes vary closely. To properly handle the former, I chose to use a logarithmic scale on the graph for these data. However, when the differences are subtle, the graph does not close any tighter than 1 order of magnitude.

    Is there a way to get the next graph to connect automatically? I have certainly seen ticks for 3.5 * 10 ^ N, not just 1 * 10 ^ N-, but now they do not appear, let alone using them as the limits of the graphic.

    I would rather not to follow the chart data in the program and property nodes allows you to change the scale by program myself!

    Right-click... scale... uncheck "loose." Also affect autoscale.

  • Is there a simple test if a cache exists without creating it?

    Is there a simple way to test if a named cache exists without creating it as CacheFactory.getCache ()?

    I am currently using a small routine which lists services and cache names until a match is found or not.
    boolean cacheExists(String name) {
        Cluster cluster = CacheFactory.getCluster();
        Enumeration<String> serviceNames = cluster.getServiceNames();
              
        while (serviceNames.hasMoreElements()) {
            Service service = cluster.getService(serviceNames.nextElement());
                
            if (service instanceof CacheService) {                         
                Enumeration<String> cacheNames = ((CacheService)service).getCacheNames();
                while (cacheNames.hasMoreElements())
                    if (cacheNames.nextElement().equals(name))
                         return true;
            }                 
        }
        return false;
    }
    Have a missed a simple way to do this?

    Kind regards
    Phil

    It's as well that we also do Phil - there was a previous post (that I can't quickly) who agreed it was the only way. Better, has.

  • How can I count the custom order?

    I'm counting the number of names that appear in all the columns in the table

    Each cell contains the name of a single individual, like the first column: 1-01, the second columns: 1-02, etc.

    Can someone help me with the formula to measure? What would be the correct formula for this?

    Thank you very much.

    Hi the learner,

    "I'm trying to count the number of names that appear in all the columns in the table

    Each cell contains the name of a single individual, like the first column: 1-01, the second columns: 1-02, etc.. »

    Your goal is not clear.

    What do you mean by ' count number per ordercustom?

    You want a single indictment which only has the names that appear in each column?

    Do you want counts of the number of names appearing in each column (ie. a separate head for each column)?

    You want a counter of the number of all the names on the table?

    Or is that what you want different from all this?

    "Each cell contains the name of a single individual."

    Not mean there is no empty cell?

    This means that there are no cells that contain data that is not the name of an individual?

    I do not understand the connection between "1-01", "1-02 ' and the names in the cells.

    Please specify.

    Kind regards

    Barry

  • USB-6210 analog in, the same channel, but the readings of two orders of magnitude different

    LV 2014

    Windows 7 Professional

    64 bit

    NEITHER USB-6210

    The vi takes two samples from the 6210 analog in, ch 0.

    Front photo shows the entrance of the canal is the same, but the two readings are 10 ^ difference size 5.

    There is a delay of one second between readings and a digital output goes high to low.

    Vi refinging admitted that she needs.

    VI joint are saved as version of 2014

    and the version of 2013, respectively.

    Well, that would be because you wrote a bug.

    Change this to AI tension!

    And stop writing bugs

  • Stabilizing warp count a lot more images than actually exists...

    Hello, everyone!

    I just installed first CC 2014 and I have problems with the stabilizer deform... I'm trying to use it in the clip with 25s and 24 frames per second, but when I click on "Analyze" it shows 1035764 images! In addition, it will take 2560 minutes to analyze all this! Do the math, it should have only something like 600 executives and take a lot less time...

    I know this stabilizer is very buggy, but I couldn't find a solution for this. Can someone help me?

    Thanks in advance!

    Well well, for some reason any randomly, if I replace each file for itself the bug go away, I had to do this one by one. If anyone has the same problem, try to do this.

    This action solves the problem for now, but it took time to discover and solve. Hopefully this won't happen again.

  • "Order By" in Exists / condition not exist cause ORA-00907 in Apex4.1.1

    Hi guys,.
    We have just improved Apex 3.2.1 to 4.1.1. on Oracle DB V11.2.0.1, while testing the apps in the apex, I encountered this problem.

    When I have a page of the process with a defined condition.
    What Type of Condition is Exists (SQL query returns at least one row) or it does not exist (SQL query returns no line) and the Expression 1 is a query with an "Order By" clause, for example
    SELECT 123 DOUBLE
    ORDER BY 1

    When the process starts, Apex 3.2.1 assess the State and run the process very well, but the Apex 4.1.1 would throw an error: ORA-00907: lack the right parenthesis

    I understand that as an order of the clause in a condition Exists or it does not exist is not necessary and agree that they shouldn't be there in the first place.
    But unfortunately I'm dealing with other codes to developers, and these conditions were coded like that, probably from copy - paste the codes.

    Saying that, I also think that an upgrade of the Apex should not stop anything that works in previous versions without warning or provide a workaround solution, right?

    I don't know if this affects other types of artifacts that may have a condition by their Summit when upgraded to 3.2.1 e.g. areas, Items, calculations, Validations etc.
    Does anyone else get this behavior? and there at - it an easy way to fix these?
    Ideally I won't go through all the processes (and some other artifacts might be affected too) in all applications in all areas of work to verify the condition type and manually remove the "Order By" clause.

    Thank you for advising them

    Just did some tests more

    'Calculation', 'Validation', 'Process' and 'Branches' have the same problem, 3.2.1 takes 'Order By' fine condition Exists/Not Exists, but 4.1.1 throws the error message.

    "The regions", "Buttons", "Items" have the constant behavior - 3.2.1 both 4.1.1 throw error ORA-00907: lack the closing parenthesis, what page is rendered.

    Published by: Danny on 04/25/2012 20:07

    Hey Danny,

    It's interesting. I just had a peek at what happens when you use an EXISTS or NOT EXISTS condition type. The following SQL statement final will be generated with your example above. You can also see that if you run your application in debug mode.

    select count(*) from sys.dual where exists (select 123 from dual order by 1)
    

    The execution of this statement within SQL * Plus will also see the error ORA-00907. It seems that the SQL parser does not have an order by clause in a clause EXIST.

    I wonder why this should have worked in previous versions, but I can only suspect that in the past we can just running

    select 123 from dual order by 1
    

    which may be a little slower, because with the new engine EXISTS SQL statement may stop treatment earlier if it finds a record.
    We try to be backwards compatible, as much as possible, but I doubt that we will change the way it was before due to the alteration of performance would be faced with 99.9% of our customers.

    Possible workaround: you might be able to use the new "search request" to analyze your application "to" fix for all the shots where the attribute name is "Expression 1".

    Concerning
    Patrick
    -----------
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • Using the mouse click simple counter

    Purpose to make a mouse click counter. (a simple button clicker/tally, which keeps the number of clicks a user sets).

    1. Progress-
      1. Done button
      2. variable passed to the completed text field.
      3. correct variable pass script to the incomplete text field.
    2. Problem-

    1 counter variable remains at 1 and does not increase by 1 when the button is clicked.

      Link to .fla

      script

      var myVar = 0;

      button_1.addEventListener (MouseEvent.CLICK, fl_ClickToPosition);

      var fl_TF:TextField;

      var fl_TextToDisplay:String = myVar;

      function fl_ClickToPosition(event:MouseEvent):void

      {

      fl_TF = new TextField();

      fl_TF.autoSize = TextFieldAutoSize.LEFT;

      fl_TF.background = true;

      fl_TF.border = true;

      fl_TF.x = 100;

      fl_TF.y = 100;

      fl_TF.text = fl_TextToDisplay;

      addChild (fl_TF);

      myVar ++;

      }

      any help is greatly appreciated.

      Thank you

      Try:

      var myVar = 0;

      button_1.addEventListener (MouseEvent.CLICK, fl_ClickToPosition);

      var fl_TF:TextField;
      fl_TF = new TextField();
      fl_TF. AutoSize = TextFieldAutoSize.LEFT;
      fl_TF. Background = true;
      fl_TF. Border = true;
      fl_TF.x = 100;
      fl_TF.y = 100;
      fl_TF. Text = String (myVar);
      addChild (fl_TF);

      function fl_ClickToPosition(event:MouseEvent):void
      {
      myVar ++;
      fl_TF. Text = String (myVar);
      }

    1. SQL execution order

      Hi friends,

      Reference post https://community.oracle.com/thread/3520158

      If the order of processing of a SQL statement is

      OF-> WHERE-> GROUP-> GET-> SELECT-> ORDER BY

      So why do I get errors in a different order:

      See for more information.

      (A). all fields are false. FROM a known first.

      SQL > SELECT EAEED

      2 FROM DEEP FISHING

      3. WHERE MODOU > 3

      GROUP 4 BY EDDEW

      5 HAVE EDEW = 5

      6 ORDER BY ERA;

      DEEP FISHING

      *

      ERROR on line 2:

      ORA-00942: table or view does not exist

      (B) correction OF the identifier clause.   [ORDER BY has been checked before WHERE]

      SQL > SELECT EAEED

      2 FROM EMP

      3. WHERE MODOU > 3

      GROUP 4 BY EDDEW

      5 HAVE EDEW = 5

      6 ORDER BY ERA;

      ORDER BY ERA

      *

      ERROR on line 6:

      ORA-00904: "ERA": invalid identifier

      (C) correction ORDERBY clause.  [HAVING been checked before GROUP BY]

      SQL > SELECT EAEED

      2 FROM EMP

      3. WHERE MODOU > 3

      GROUP 4 BY EDDEW

      5 HAVE EDEW = 5

      6 ORDER BY ENAME;

      AFTER YOU HAVE EDEW = 5

      *

      ERROR on line 5:

      ORA-00904: "EDEW": invalid identifier

      (D). WITH withdrawal clause.

      SELECT EAEED

      FROM EMP

      WHERE MODOU > 3

      EDDEW GROUP

      -HAVE EDEW = 5

      ORDER BY ENAME;

      (E) correction Group by

      SQL > SELECT EAEED

      2 FROM EMP

      3. WHERE MODOU > 3

      GROUP 4 BY EMPNO

      5 WITH EDEW = 5

      6 ORDER BY ENAME;

      WHERE MODOU > 3

      *

      ERROR at line 3:

      ORA-00904: "MODOU": invalid identifier

      (F) fixed WHERE

      SQL > SELECT EAEED

      2 FROM EMP

      3. WHERE deptno <>10

      GROUP 4 BY EMPNO

      5 WITH EDEW = 5

      6 ORDER BY ENAME;

      SELECT EAEED

      *

      ERROR on line 1:

      ORA-00904: "EAEED": invalid identifier

      (G). SELECT correction

      SELECT EMPNO

      FROM EMP

      WHERE deptno <>10

      GROUP BY EMPNO

      VIEW count (*) > 1

      ORDER BY Empno;

      EMPNO

      ----------

      7369

      7499

      7521

      7566

      7654

      7698

      7788

      7844

      7876

      7900

      7902

      11 selected lines.

      This means SQL executed in different order, or there is some reason to get error in that order?

      Hello

      Kimmy says:

      HI Frank and Baris,

      Is that means there is a defined order for execution of SQL to oracle but compiling the SQL statement has no order defined by the (FROM, WHERE, GROUP BY) clauses and compilation may give error in any order, and which will compile all first does matter?

      Kind regards

      The system can choose to compile an SQL statement in any order.  I have never seen a case where this order is significant to anyone.  (I don't know what is important to you.)

      If your code has compile errors, you will get only 1 error message, and the message can be caused by any line of your code.  If your SQL statement has 10 lines, and you get an error message referring to line 5, there may be other errors as well.  If there is another error, could be on lines 1-4, or it could be on lines 6-10, it could be elsewhere on line 5.

      There is a relationship between the clauses in your code and the order in which the code is run.  For example, the compiled code corresponding to a condition of a FROM clause join will probably run before the compiled code corresponding to the ORDER byclause of this request.  The rules specifying the 'order' can be useful, but should not be taken too literally.

    2. Count total count (*)

      Hello

      I'm writing a select statement that returns the number of child records for each parent where the status of the parent record is 'I' (for non valid). referring to the following query:

      Select PK_value,
      Count (*) as CNT
      of child_table C
      where exists (select 'X' parent_table P
      where P.status = 'I '.
      and P.PK_value = C.PK_value
      )
      C.PK_value group
      /

      but I woud also like the total number of children records in the query above, is this possible?

      I searched this forum and the web in general and not found an answer that works. Any help or advice would be appreciated!

      Steve

      Hi, Steve,.

      You can do this by using GROUP BY ROLLUP .
      Given that you do not post test versions of your tables, I will use CMII in the scott schema to illustrate.
      To count is the number of employees in each Department and not located in Chicago, you can do this:

      SELECT       CASE
                WHEN  GROUPING (e.deptno) = 0
                THEN  TO_CHAR (e.deptno)
                ELSE  '  Total'
             END               AS deptno
      ,       COUNT (*)          AS cnt
      FROM       scott.emp   e
      JOIN      scott.dept  d  ON  e.deptno     = d.deptno
      WHERE     d.loc  != 'CHICAGO'
      GROUP BY  ROLLUP (e.deptno)
      ORDER BY  e.deptno
      ;
      

      Output:

      DEPTNO            CNT
      ---------- ----------
      10                  3
      20                  5
        Total             8
      

      I hope that answers your question.
      Otherwise, that, as others have said, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also to post the results desired from these data.
      Explain, using specific examples, how you get these results from these data.
      Always tell what version of Oracle you are using.

      Published by: Frank Kulash on 12 March 2012 18:14
      Example of change

    3. Question of the order of events and functions

      Hello

      Sorry for the stupid question, but I'm working on something big and I would hate a small rock to thow me off in the end.

      So here it is:

      I not know how to operate the functions-> if you have:

      function function1() {}

      function3();

      }

      function function2() {}

      }

      function function3() {}

      }

      function1();

      function2();

      First runs function1 and function2 and function3. Is simple baptisms the function1 + everything it has nested functions again from the top to the bottom, then function2 etc.

      OK, so now I have this situation:

      If you have an INTERNAL component that is in the MAIN component. If you addEventListener (FlexEvent.CREATION_COMPLETE, test) inside of the INSIDE (class of the function of construction in my case) and also add the same event listener once again inside but the MAIN ingredient such as:

      public void main_creationCompleteHandler(event:FlexEvent):void {}

      inner.addEventListener (FlexEvent.CREATION_COMPLETE, test);

      addElement (inner);

      }

      Then you will have 2 event for the same event listeners. First one written to the INNER component will run, and then it will run in the MAIN component.

      Now if I set many many functions in INNER creationCompleteHandler, will all 100% complete before the creationCompleteHandler to HAND work?

      As I tested it, it looks like each treatment must be 100% made to the INNER creationCompleteHandler before it passes to the creationCompleteHandler of HAND.

      Can someone confirm that flash/flex works like that? Thank you!

      FM_Flame wrote:

      Hi Alex, guys,.

      so, I would like to summarize the question and if we can just say Yes or I guided even what is Yes, then there is no confusion

      Here are 2 scenarios:

      1) 2 headphones are added to the same same thing e.g. CREATION_COMPLETE - one for the component and the other to the container.

      It works like this:

      un) pane-> creationCompleteHandler starts to perform its functions/activities

      b) containing-> creationCompleteHandler starts to perform its functions/activities

      The question here is: will a) be 100% full before before flash moves to b) or b) could happen sometimes some time one) is running?

      Note: Yes this means a) will be 100% complete bofore b) occurs.

      2) for the second scenario allows to take 2 different events INITIALIZE and the FlexEvent CREATION_COMPLETE and add the listener both in the component only this time, so we do not complicate things.

      It works like this:

      un) pane-> initializeHandler starts to perform its functions/activities

      b) pane-> creationCompleteHandler starts to perform its functions/activities

      The question here is the same: will a) be 100% full before before flash moves to b) or b) could happen sometimes some time one) is running?

      Note: Yes this means a) will be 100% complete bofore b) occurs.

      Thank you very much

      (1) flash is currently single-threaded, so a Manager will end before the end of another Manager for the event itself. The processing order is not guaranteed and since your handlers are listening for the event attached to the same object, that it is imprudent to write code that depends on the order in which these handlers are called. Adobe are working to multi-threading the flash plugin, in the future any order that may now exist differrent in the future and any treatment that depends on a single completion handler until the other is called can also fail in the future because a multi-threaded player could activate the two managers simultaneously.

      It's nice to have answers Yes/No, but only if you want to write poor code that can work, by accident, until something changes that you have no control over.

      Do not write code that depends on the order this event handler is called for the same event.

      (2) initialize occurs before the complete creation. The answer is Yes.

    4. Free run event counter when counter source is low

      Hi all

      I'm trying to implement a counter of simple events on a 6036 using NiDaq and VB6.  I have connected a quadrature encoder to board one on pin of counter0src phase. Configure the counter is a counter of events, not winnowed. Start the meter and all is ok except when the counter0src PIN is low, the meter will record the random impulses. A voltmeter attached to pin watch 0.0 x volts and no tension noticeable glitches. If I short the PIN to ground, it has found no consideration, false impulses themselves.

      Any thoughts?

      Dan

      That's the information I was looking for, even if it wasn't what I wanted to hear!

    5. Order of query

      Hello

      I have this query, but it does not correctly order DATE1 column.

      SELECT NULL LINK,
              TO_CHAR(d, 'HH24')|| ' h.' AS date1,
              ROUND(MAX(v) OVER(PARTITION BY g), 2) AS valeur
              FROM
              (SELECT d, v, COUNT(v) OVER(ORDER BY d) AS g
               FROM
               (SELECT d, AVG(valeur) AS v
                FROM evv_st25,(SELECT TO_DATE('03/11/2014', 'DD/MM/YYYY') + (LEVEL - 1) / 24 AS d
                               FROM DUAL CONNECT BY LEVEL <= 24)
            WHERE date1(+) >= d
          AND date1(+)      < d + 1 / 24
          AND clef_var(+) = 3991
         GROUP BY d
         ORDER BY d
          )
        )
      

      As you can see from this screenshot, the DATE1 column is not correctly sorted as hours, days, for example on line 11, it is 06 h. and on line 12, 22 h.

      Capture.JPG

      I wish that the DATE1 column sorted properly as hours of the day.

      Thank you.

      Hi Christian,

      It is a little more complex, I think.

      Try this

      ksdfskdg
      
      SELECT NULL
      AS LINK,  
      
      TO_CHAR(d, 'HH24')|| ' h.'
      AS date1,  
      
      ROUND(MAX(v) OVER(PARTITION BY g), 2) AS valeur  
      
        FROM  
      
      (SELECT d, 
      
      v, 
      
      COUNT(v) OVER(ORDER BY d) AS g  
      
      FROM  
      
      (SELECT d,
      
      AVG(valeur) AS v  
      
      FROM evv_st25,
      
      (SELECT TO_DATE('03/11/2014', 'DD/MM/YYYY') + (LEVEL - 1) / 24 AS d FROM DUAL CONNECT BY LEVEL <= 24)  
      
      WHERE
      date1(+) >= d  
      
      AND
      date1(+)  < d + 1 / 24  
      
      AND clef_var(+)  = 3991  
      
      GROUP BY d  
      
      --
      ORDER BY d  -- no need to sort here
      
      )    
      
      )
      
       order by 2;  
      

      concerning
      Kay

    6. Row counter

      I am currently building a count field that increments for groups of consecutive lines.

      
      SELECT EMPLOYEE_ID,
             DTE,
             HOURS,
             JOB,
             ACTIVITY
        FROM (SELECT EMPLOYEE_ID,
                     DTE,
                     HOURS,
                     JOB,
                     ACTIVITY_CDE,
                     LAG (JOB, 1, JOB) OVER (ORDER BY DTE)
                        AS prev_jobnum,
                     LEAD (JOB, 1, JOB) OVER (ORDER BY DTE)
                        AS next_jobnum
                FROM tablename
               WHERE     T_YEAR >= '2012'
                     AND EMPLOYEE_ID = '1234'
                     AND HOURS >= '8'
                     
       WHERE     JOB = 'SICK'
             AND (JOB = prev_jobnum OR JOB = next_jobnum)
      

      The result:

      EMPLOYEE_IDDTEHOURSJOBACTIVITYSICK_COUNTER
      123411/03/20137SICKGENLV1
      123412/03/20137SICKGENLV2
      123419/02/20147SICKGENLV3
      123420/02/20147SICKGENLV4
      123421/02/20147SICKGENLV5
      123407/08/20147HOLIDAYGENLV1
      123408/08/20147HOLIDAYGENLV2

      I need the meter to zero when it's not the same consecutive game.  The result should look like this:

      EMPLOYEE_IDDTEHOURSJOBACTIVITYSICK_COUNTER
      123411/03/20137SICKGENLV1
      123412/03/20137SICKGENLV2
      123419/02/20147SICKGENLV1
      123420/02/20147SICKGENLV2
      123421/02/20147SICKGENLV3
      123407/08/20147HOLIDAYGENLV1
      123408/08/20147HOLIDAYGENLV2

      Any ideas?

      OK, this is my last attempt for today.

      If test you it, don't forget some cases with the holidays.

      If you a protection requirements were implemented properly, perhaps we can find a less cumbersome approach:

      with pre_grps like)

      Select

      employee_id

      dte

      hours

      work

      activity

      -1 start of a new group of sick, 0 no group start, -1 start again no group sick

      When job = 'ILL' - sick with precessor ('sick', 'HOLIDAYS') and the offset in hours > = 7 cannot be a new group

      and offset (employment) over (partition by employee_id) stopped by dte ('sick', 'HOLIDAY')

      and the offset (in hours) over (partition by employee_id) stopped by dte > = 7

      then 0

      When job = 'HOLIDAY '.

      so to case when lag (job 1, employment) over (partition by employee_id stopped by dte) = "SICK".

      and offset (hours, 1, 0) over (partition by employee_id stopped by dte) > = 7

      and lead(job,1,job) over (partition by employee_id stopped by dte) = "SICK".

      and lead (hours, 1, 0) over (partition by employee_id stopped by dte) > = 7

      then 0 - holiday cant never be the beginning of a group of consecutive sick if it is included by sick

      -Hypothesis: entry only vacation between two entrances for SICK

      1 other

      end

      1 other

      end grp_flag

      , case when work = 'HOLIDAY '.

      so to case when lag (job 1, employment) over (partition by employee_id stopped by dte) = "SICK".

      and offset (hours, 1, 0) over (partition by employee_id stopped by dte) > = 7

      and lead(job,1,job) over (partition by employee_id stopped by dte) = "SICK".

      and lead (hours, 1, 0) over (partition by employee_id stopped by dte) > = 7

      then "SICK".

      another job

      end

      another job

      end job_drv

      from the data

      )

      grps as)

      Select

      employee_id

      dte

      hours

      work

      activity

      sum (grp_flag) on the grp (partition by employee_id stopped by dte)

      job_drv

      of pre_grps

      )

      Select

      employee_id

      dte

      hours

      work

      activity

      , sum (case when job_drv = 'SICK' then 1 else 0 end) on counter (partition employe_id, order of grp by dte)

      - or perhaps better

      -, case when job_drv = "SICK".

      -then sum (1) (partition employe_id, order of grp by dte)

      -0 otherwise

      -end meter

      PEB

      order by employee_id, dte, counter

    Maybe you are looking for