Looking for Analytical function to filter query

Source dataset for one of policy
PC_COVKEY     POLICY_NUMBER     TERM_IDENT     COVERAGE_NUMBER     TRANSACTION_TYPE     COV_CHG_EFF_DATE     TIMESTAMP_ENTERED
10897523P7013MC0010072     10897523P7     013     001     10     17/NOV/2008     20/NOV/2008 05:36:45.482025 PM
10897523P7013MR0030062     10897523P7     013     003     10     17/NOV/2008     20/NOV/2008 05:36:45.514349 PM
10897523P7013MC0010062     10897523P7     013     001     03     20/NOV/2008     20/NOV/2008 05:26:13.205097 PM
10897523P7013MR0030052     10897523P7     013     003     03     20/NOV/2008     20/NOV/2008 05:26:42.587605 PM
10897523P7013MC0010082     10897523P7     013     001     07     20/NOV/2008     20/NOV/2008 05:36:51.605820 PM
10897523P7013MR0030072     10897523P7     013     003     07     20/NOV/2008     20/NOV/2008 05:36:51.971094 PM
10897523P7013MC0010092     10897523P7     013     001     03     20/NOV/2008     23/MAR/2010 04:00:21.801816 PM
10897523P7013MR0030082     10897523P7     013     003     03     20/NOV/2008     23/MAR/2010 04:03:01.402111 PM
Filter records
10897523P7013MC0010062     10897523P7     013     001     03     20/NOV/2008     20/NOV/2008 05:26:13.205097 PM
10897523P7013MR0030052     10897523P7     013     003     03     20/NOV/2008     20/NOV/2008 05:26:42.587605 PM
Rule:
Row with transaction_type 03's after a group 09 or 10 before the next 07 or 06

Like this?
with t
as
select '10897523P7013MC0010072' pc_covkey, '10897523P7' policy_number, '013' term_ident, '001' coverage_number, '10' transaction_type,     to_date('17/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('20/NOV/2008 05:36:45.482025 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MR0030062' pc_covkey, '10897523P7' policy_number, '013' term_ident, '003' coverage_number, '10' transaction_type,     to_date('17/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('20/NOV/2008 05:36:45.514349 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MC0010062' pc_covkey, '10897523P7' policy_number, '013' term_ident, '001' coverage_number, '03' transaction_type,     to_date('20/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('20/NOV/2008 05:26:13.205097 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MR0030052' pc_covkey, '10897523P7' policy_number, '013' term_ident, '003' coverage_number, '03' transaction_type,     to_date('20/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('20/NOV/2008 05:26:42.587605 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MC0010082' pc_covkey, '10897523P7' policy_number, '013' term_ident, '001' coverage_number, '07' transaction_type,     to_date('20/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('20/NOV/2008 05:36:51.605820 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MR0030072' pc_covkey, '10897523P7' policy_number, '013' term_ident, '003' coverage_number, '07' transaction_type,     to_date('20/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('20/NOV/2008 05:36:51.971094 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MC0010092' pc_covkey, '10897523P7' policy_number, '013' term_ident, '001' coverage_number, '03' transaction_type,     to_date('20/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('23/MAR/2010 04:00:21.801816 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
union all
select '10897523P7013MR0030082' pc_covkey, '10897523P7' policy_number, '013' term_ident, '003' coverage_number, '03' transaction_type,     to_date('20/NOV/2008', 'dd/MON/yyyy') cov_chg_eff_date, to_timestamp('23/MAR/2010 04:03:01.402111 PM', 'dd/MON/yyyy hh:mi:ss.ff PM') timestamp_entered from dual
select *
  from (
          select lag(transaction_type) over(order by cov_chg_eff_date, timestamp_entered) prev,
                 lead(transaction_type) over(order by cov_chg_eff_date, timestamp_entered) post,
                 t.*
            from t
where transaction_type = '03'
   and prev in ('03', '09', '10')
   and post in ('03', '07', '06')
  

Similar Messages

  • Analytical function to filter query

    Source dataset for one of policy
    PC_COVKEY POLICY_NUMBER TERM_IDENT COVERAGE_NUMBER TRANSACTION_TYPE COV_CHG_EFF_DATE TIMESTAMP_ENTERED
    10695337P3021MC0020012     10695337P3     021     002     02     22/OCT/2011     22/SEP/2011 03:10:12.523408 AM
    10695337P3021MC0010012     10695337P3     021     001     02     22/OCT/2011     22/SEP/2011 03:10:12.523508 AM
    10695337P3021MC0040012     10695337P3     021     004     02     22/OCT/2011     22/SEP/2011 03:10:12.864153 AM
    10695337P3021MC0040032     10695337P3     021 004     03     22/OCT/2011     22/SEP/2011 03:10:12.865153 AM
    10695337P3021MC0050012     10695337P3     021     005     02     22/OCT/2011     22/SEP/2011 03:10:12.976483 AM
    10695337P3021MC0020042     10695337P3     021     002     09     22/NOV/2011     16/FEB/2012 02:26:00.606435 PM
    10695337P3021MC0040042     10695337P3     021     004     09     22/NOV/2011     16/FEB/2012 02:26:00.135059 PM
    10695337P3021MC0050042     10695337P3     021     005     09     22/NOV/2011     16/FEB/2012 02:26:00.253340 PM
    10695337P3021MC0020042     10695337P3     021     002     03     22/NOV/2011     16/FEB/2012 02:26:00.363340 PM
    10695337P3021MC0040032     10695337P3     021     004     03     29/DEC/2011     16/FEB/2012 02:26:00.463340 PM *
    10695337P3021MC0050032     10695337P3     021     005     03     29/DEC/2011     16/FEB/2012 02:26:00.563340 PM *
    10695337P3021MC0020012     10695337P3     021     001     03     30/DEC/2011     16/FEB/2012 02:26:00.663340 PM
    Filter records
    10695337P3021MC0040032     10695337P3     021     004     03     29/DEC/2011     29/DEC/2011 11:21:27.745431 AM
    10695337P3021MC0050032     10695337P3     021     005     03     29/DEC/2011     29/DEC/2011 11:24:55.484547 AM
    Rule:
    Should filter rows with transaction_type 03 that appear after transaction type '09' or '10' for the each COVERAGE_NUMBER on different COV_CHG_EFF_DATE date. In the above example, 002, 004 and 005 cover are closed (transaction 09) and followed by 4 records with transaction 03.
    Out of which only 2 records should filter because cover (04 and 05) are closed and on different COV_CHG_EFF_DATE date.

    Hi,
    966820 wrote:
    Source dataset for one of policy
    PC_COVKEY POLICY_NUMBER TERM_IDENT COVERAGE_NUMBER TRANSACTION_TYPE COV_CHG_EFF_DATE TIMESTAMP_ENTERED
    10695337P3021MC0020012     10695337P3     021     002     02     22/OCT/2011     22/SEP/2011 03:10:12.523408 AMAs you learned in your last message, {message:id=10649022} , you need to post CREATE TABLE and INSERT statements for the sample data.
    Please read the forum FAQ {message:id=9360002}
    ... Filter records
    10695337P3021MC0040032     10695337P3     021     004     03     29/DEC/2011     29/DEC/2011 11:21:27.745431 AM
    10695337P3021MC0050032     10695337P3     021     005     03     29/DEC/2011     29/DEC/2011 11:24:55.484547 AMWhat are "filter records"? Are they the results you want? Are they rows in another table? Are they rows in the same table? If so, how can you tell if a row is a "filter record" or not?
    If the rows above are not the results you want, what are the correct results? Post them, formatted, between \ tags.
    Rule:
    Should filter rows with transaction_type 03 that appear after transaction type '09' or '10' for the each COVERAGE_NUMBER on different COV_CHG_EFF_DATE date. In the above example, 002, 004 and 005 cover are closed (transaction 09) and followed by 4 records with transaction 03.
    Out of which only 2 records should filter because cover (04 and 05) are closed and on different COV_CHG_EFF_DATE date.LAST_VALUE, as used in your last message, can help here.
    You should be able to do most of this query yourself by now.  Post your best attempt, and a specifc question about the trouble you're having with the remainder.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • From analytical function to regular query

    Hi all,
    I was reading a tutorial for analytical function and i found something like this
    sum(princial) keep(dense_rank first order by d_date) over partition by (userid, alias, sec_id, flow, p_date)
    can somebody translate this into simple queries / subquery? i am aware that analytical function are faster but i would like to know
    how this can translate to regular query.
    can someone help me writing a regular query that will be produce same result as query above?
    . thanks
    Edited by: Devx on Jun 10, 2010 11:16 AM

    Hi,
    WITH CUSTOMERS AS
    SELECT 1 CUST_ID ,'NJ' STATE_CODE,1 TIMES_PURCHASED FROM DUAL UNION ALL
    SELECT 1,'CT',1 FROM DUAL UNION ALL
    SELECT 2,'NY',10 FROM DUAL UNION ALL
    SELECT 2,'NY',10 FROM DUAL UNION ALL
    SELECT 1,'CT',10 FROM DUAL UNION ALL
    SELECT 3,'NJ',2 FROM DUAL UNION ALL
    SELECT 4,'NY',4 FROM DUAL
    SELECT SUM(TIMES_PURCHASED) KEEP(DENSE_RANK FIRST ORDER BY CUST_ID ASC) OVER (PARTITION BY STATE_CODE) SUM_TIMES_PURCHASED_WITH_MIN,
           SUM(TIMES_PURCHASED) KEEP(DENSE_RANK LAST ORDER BY CUST_ID) OVER (PARTITION BY STATE_CODE) SUM_TIMES_PURCHASED_WITH_MAX,
           C.*
    FROM   CUSTOMERS C;
    SUM_TIMES_PURCHASED_WITH_MIN     SUM_TIMES_PURCHASED_WITH_MAX     CUST_ID     STATE_CODE     TIMES_PURCHASED
    11     11     1     CT     10
    11     11     1     CT     1
    1     2     3     NJ     2
    1     2     1     NJ     1
    20     4     4     NY     4
    20     4     2     NY     10
    20     4     2     NY     10The above given example is self explanatory, execute the SQL, you'll notice that in the first column the sum of TIMES_PURCHASED partitioned by state code of FIRST cust_id will be repeated for the STATE_CODE partition, in the second column, the sum of TIMES_PURCHASED partitioned by state code of LAST cust_id will be repeated for the STATE_CODE partition.
    HTH
    *009*
    Edited by: 009 on Jun 10, 2010 10:53 PM

  • Looking for a "color pass filter"..Remove all colors but 1

    Looking for a "color pass filter"..Remove all colors but 1 or 2.
    FCP6 doesn't seem to have one.
    Anyone heard of one that works really well & that is fast to use?
    steve

    Jim,
    You are totally missing the point. I am an Adobe Premiere Pro instructor. I have been for 5 years. I added my 1st FCP system 2 weeks ago & am experiencing typical transitional curiosities as all who switch to other platforms & editing apps do.
    PP has a color pass filter. I was curious to see if FCP did. That sounds logical to me:) If posting the question about the possibility of there being a color pass plugin bothers you, well , that has to do with you.
    If you take a moment to read the prior correspondence, you might see my point.
    I think we can bury the hatchet now:)

  • BCG Brightness Contrast Gamma - Looking for BCG function returning color table / lookup table coded in pure G and applicable to Intensity Graph or Picture Control

    Looking for BCG function returning color table / lookup table coded in
    pure G and applicable to 8-bit Intensity Graph or Picture Control. Do
    not want to use IMAQ Vision is this particular application.  Any
    help is appreciated.
    Sincerely,
    Don

    Take a look at this color model software I put together.  (Don't concern yourself much with the basic programming at this point.). The color component generator subVI is borrowed from a LabVIEW example.
    First look at test_color2.vi.  If you adjust the sliders of the various controls, you will see how it works.  You can see that for pure B&W images, brightness, contrast, and gamma (which I think I have coded correctly) are all fairly straightforward to modify.
    Now look at test_color3.vi.  Here we try to adjust BCG for color images using the color model shown here where current color component clusters are carried into the BCG event cases via shift registers.  You can see that once color is introduced into the image, it becomes difficult to mix the colorizing with the BCG model.  And this is pretty much where I am right now.
    Would be interested in comments / suggestions.
    Sincerely,
    Don
    Attachments:
    test_color2.llb ‏2251 KB

  • Looking for best way to filter status or meter data from differently formatted text.

    With the product we design we are able to communicate via RS-232 ports. What I'm trying to do is filter out the data that is given by multiple differnt types of products that will give similar data back, but in a differnt format. Such that in a status command I'm looking for everything to be in a non failed state. But some items will show warning, failure, #.##w(for warning), or #.##f (for fail). But the format of each product is different. Also for a meter command I'm looking for a way to filter out just the numeric value for each phase amplitude, but once again the format will be different for each product. I have been able to pull this data out easy enough for an individual product but not on a wide product range with the same VI.

    "Service is not available at this time
    Try back later"
    Bye...
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • We look for BAPI/Function to As-Built for Serialized Material (tran.COIB)

    Hello ,
    We look for BAPI/Function to As-Built for Serialized Material (transaction COIB).
    We check transaction COIB in order to create insatlled base for production orders(bill of equipments)
    We look for BAPI/ Function in order to run that process automatically in background base of some rules we will decide. Do you know if there is BAPI/ Function  refer to it?

    Sorry but I found the function group IBPP with the function modules:
    IBPP_CHANGE_IBASE
    IBPP_CREATE_IBASE
    IBPP_GET_IBASE_DOWN_ALL
    For our requirements these fmodules are sufficient.
    Regards

  • Mutt: looking for a function

    hi,
    i'm looking for a function in mutt that prints user defined text in the line below the status bar. it would be nice if user defined macros would output text like "Moved message to ...", like some internal functions do it.
    ccc1

    See if this helps
    https://sites.google.com/site/sqlblindman/fuzzysearchalgorithm
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Alternate for analytic functions

    Hello All,
    I'm trying to write a query without using analytic functions.
    Using Analytic func,
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE     11.2.0.2.0     Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    SELECT id, sal, rank() OVER (PARTITION BY ID ORDER BY SAL) rnk FROM
    (SELECT 10 AS id, 100 AS sal FROM DUAL
        UNION ALL
        SELECT 10, 300 FROM DUAL
        UNION ALL
        SELECT 10, 400 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 300 FROM DUAL
        UNION ALL
        SELECT 30, 100 FROM DUAL
        UNION ALL
        SELECT 40, 100 FROM DUAL
        UNION ALL
        SELECT 40, 200 FROM DUAL
        ) Expected results. I want these results without analytic functions.
    10     100     1
    10     300     2
    10     400     3
    20     200     1
    20     200     1
    20     300     3
    30     100     1
    40     100     1
    40     200     2

    Hi,
    SamFisher wrote:
    Thank You Frank. That was simple.
    I was trying to get the reults without using analytical functions. Just trying to improve my SQL skills. Yes, I admit that practicising using the wrong tools can improve your SQL skills, but I think there's a lot to be said for practising using the right tools, too.
    I tried all sort of things. I thought hierarchical query would do it but hard luck for me.Do you want to use a CONNECT BY query for this? Here's one way:
    WITH     got_max_level            AS
         SELECT       id
         ,       sal
         ,       MAX (LEVEL)     AS max_level
         FROM       table_x
         CONNECT BY NOCYCLE  id        = PRIOR id
              AND          sal       >= PRIOR sal
              AND     (   sal       >  PRIOR sal
                   OR  ROWID > PRIOR ROWID
         GROUP BY  id
         ,            sal
    ,     got_cnt          AS
         SELECT       id
         ,       sal
         ,       COUNT (*)     AS cnt
         FROM       table_x
         GROUP BY  id
         ,            sal
    SELECT       x.id
    ,       x.sal
    ,       l.max_level + 1 - c.cnt     AS rnk
    FROM       table_x        x
    JOIN       got_max_level  l  ON   x.id     = l.id
                         AND      x.sal     = l.sal
    JOIN       got_cnt      c  ON      x.id     = c.id
                         AND      x.sal     = c.sal
    ORDER BY  x.id
    ,            x.sal
    ;This is even less efficient, as well as more complicated, than the scalar sub-query solution.

  • Looking for NIDAQ Functions/​Examples for 'Analog I/O DMA' and 'Digital I/O DMA'. (I am using 6024,6503 boards and VC++ in my project)

    I am using 6024,6503 boards. I need to implement AnalogInputDMA /AnalogOutputDMA,DigitalInputDMA and DigitalOutputDMA blocks for another software. Why there are no NIDAQ functions used with 'DMA' ?

    Alan;
    The NI-DAQ doesn;t have any functions to specifically access the DMA transfers, because that is done automatically for you. Once you set the data transfer to use the DMA channels, all the rest is handled by the driver.
    Once you set up an Analog input task, and select the data transfer to use the DMA channels, you won't have access to the DMA channels but to the datapoints after the transfer.
    Regarding the digital side of the application, I think that what you are looking for is a pattern input/output type of application, that will use DMAs for data transfer.
    The 6503 doesn't offer that functionality. To accomplish that application, you will need one of the board of the 653x family.
    Hope this helps.
    Filipe A.
    Applications Engineer
    National
    Instruments

  • Looking for Financials Functional Expert - $100/Hr + Contract Opportunity

    Our company has been looking for Oracle Financials functional consultants who have implemented the below modules for other organizations - iReceivables, iPayables, Adv. Collections and LockBox
    This is an existing EBS installation with A/R already implemented. We need an expert who can help us implement the above new modules.
    Pl. respond with resume and contact info to [email protected]
    Thanks

    Hi sir,
    I am currently working in a MNC, as an engineer. I am keenly interested in Labview, and i know basics of it.
    Attached is my resume. I would like to work with Labview.
    Regards,
    Pooja karnani
    Attachments:
    RESUME.docx ‏30 KB

  • Looking for an old videotape filter

    I'm looking for a filter that when applied makes my video look like old videotape. Wrinkles, rolls etc. I already have the filter that makes it look like old film but its not quite the look that I'm looking for. Any ideas where I can find one?

    Thanks for the suggestion, Tracky, but that's not exactly what I was looking for, thats more of an old film look instead of a worn out video tape.
    After looking at my version of Final Cut Express 4.0.1, looks like I don't have the Bad TV filter either.....bummer.

  • Question for analytic functions experts

    Hi,
    I have an ugly table containing an implicit master detail relation.
    The table can be ordered by sequence and then each detail is beneath it's master (in sequence).
    If it is a detail, the master column is NULL and vice versa.
    Sample:
    SEQUENCE MASTER DETAIL BOTH_PRIMARY_KEYS
    1____________A______________1
    2___________________A_______1
    3___________________B_______2
    4____________B______________2
    5___________________A_______3
    6___________________B_______4
    Task: Go into the table with the primary key of my detail, and search the primary key of it's master.
    I already have a solution how to get it, but I would like to know if there is an analytic statement,
    which is more elegant, instead of selfreferencing my table three times. Somebody used to analytic functions?
    Thanks,
    Dirk

    Hi,
    Do you mean like this?
    with data as (
    select 1 sequence, 'A' master, null detail, 1 both_primary_keys from dual union all
    select 2, null, 'A', 1 from dual union all
    select 3, null, 'B', 2 from dual union all
    select 4, 'B', null, 2 from dual union all
    select 5, null, 'A', 3 from dual union all
    select 6, null, 'B', 4 from dual )
    select (select max(both_primary_keys) keep (dense_rank last order by sequence)
            from data
            where sequence < detail_record.sequence and detail is null) master_primary_key
    from data detail_record
    where (both_primary_keys=3 /*lookup detail key 3 */  and master is null)

  • 2.1 EA Bug: group by auto complete generates group by for analytic function

    Hi,
    when using an analytic function in the sql text, sqldeveloper generates an automatic group by statement in the sql text.
    Regards,
    Ingo

    Personally, I don't want anything changed automatically EVER. The day you don't notice and you run a wrong statement, the consequences may be very costly (read: disaster).
    Can this be turned off all together? If there's a preference I didn't find, can this be left off by default?
    Thanks,
    K.

  • Looking for Techno-functional freelancer in peoplesoft 9.2

    Hello Guys,
    My company is looking for a freelance who can help us to integrate Resume Parser with our existing PeopleSoft Insatallation with HCM/TAM 9.2.
    Please contact me asap.
    Thanks.

    Sounds like it could be a browser issue.  UPk 11.0.x is quite old and does not support the latest browsers for recording purposes.  What browser (and version of the browser) are you using with UPK 11.0 SP1?

Maybe you are looking for

  • My web cam is not working, I downloaded a update of the web cam it was a 15 day trial, I dec ided I

    I downloaded a updated version of the web cam installed on my laptop, it was a version 5, this is what I was told that would come with the laptop, is was a 15 day trial, I decided I didn't want to purchase it, and now my web cam is not working

  • Unable to Define Business System in SLD.

    Hi All, We configured SLD host on EPDEV system (EP System based on Only Web as Java). We have diffrent system for PI. At the time of PI installation I mentioned SLD Host as EP system. In PI am facing some problem while executing SLDCHECK, output as "

  • Inspection lot qty printout

    Dear all, I have a requirement of a tag printing in which inspection lot details are being printed. The Tag being printed every time of partial UD, here the problem in printing of the tag observed. The tag contains the inspection lot cleared qty, but

  • Making window active when mouse pointer moves over it?

    As the subject line says, how do I configure Mac OS X such that a window automatically becomes the active one (also in the menu bar) when the mouse pointer moves over it? If possible, with a slight delay?

  • How do I right click on OLD Apple mouse that is white / oval shape?

    How do I right click on the older version of Apple mouse? Please do not tell me to buy a new one, I myself have new mac mini with trackpad, but need to help friend in wheelchair who lives in healthcare facility fix an app on his iMac, need to right c