SQL query to dynamically filter the records-need help

Hello

I have a table with the structure as below

Create table T1
(Number (5) ID,)
Action Varchar2 (20)
)


Here's the table of contents at different points in time and please help me with a query that must dynamically discover the results according to the entries in the table.

First Table contents

1 pending
2 waiting


Result of the query must be

1 pending
2 waiting


After an insert the Table of contents

1 pending
2 waiting
3 ignored

Result

Nothing should be displayed


After an insert the Table of contents
1 pending
2 waiting
3 ignored
4 ignored

Result
Nothing should be displayed

After an insert the Table of contents
1 pending
2 waiting
3 ignored
4 ignored
5 in queue

Result
5 in queue

Thanks in advance!

Best regards
Sridhar

Hi, Sridhar,

So you want to show t1 lines that come after the last row with action = "Ignored", which means no output at all during the last row has action = "ignored". (A line with a given id is considered as ' after' a line with a lower id. The line with the highest id is considered the "last" line.)
Is this fair?

Here's one way:

SELECT     *
FROM     t1
WHERE     id  > (
          SELECT  MAX (id)
          FROM     t1
          WHERE     action     = 'Ignored'
           )
;

It's not assume this id is whole consecutive.

If the id is not unique, what results do you want? There is a chance that the above query is already doing if this is not the case, it can probably be changed.

Tags: Database

Similar Questions

  • SQL query to retrieve a single record for each employee of the following table?

    Hi all

    Help me on the writing of SQL query to retrieve a single record for each employee of the following table? preferably a standard SQL.

    CREATE TABLE xxc_contact)

    empnum NUMBER,

    alternatecontact VARCHAR2 (100),

    relationship VARCHAR2 (10),

    phtype VARCHAR2 (10),

    Phone NUMBER

    );

    insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Cell', 9999999999)

    insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Work', 8888888888)

    insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Work', 7777777777)

    insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Home', 3333333333)

    insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Cell', 9999999999)

    insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Home', 9999999999)

    expected result:

    EmpNum AlternateContact Relationship PhType Phone       

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    Thanks in advance.

    994122 wrote:

    Thank you all, that I got a result

    http://www.orafaq.com/Forum/m/620305/#msg_620305

    By Lalit Kumar B...

    Specifically, the two simple solutions provided were:

    1 using the row_number, entitled Oracle ranking based on descending order of the inside telephone each empnum group. And finally selects the lines which has least rank (of least since that order is descending for phone).

    SQL > column alternatecontact format A20;

    SQL >

    SQL > SELECT empnum, alternatecontact, relationship, phtype, phone

    2 from (SELECT a.*, row_number() over r (PARTITION BY empnum ORDER BY phone / / DESC))

    3 FROM xxc_contact one)

    4. WHEN r = 1

    /

    EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE

    ---------- -------------------- ---------- ---------- ----------

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    2. with the help of MAX, Oracle automatically assigns the maximum phone for all the rows in each group of empnum. And finally selects the rows with the maximum phone. Order by clause is omitted here intentionally. You can find out why.

    SQL > SELECT empnum, alternatecontact, relationship, phtype, phone

    2 (SELECT a.*, MAX (phone) over (PARTITION BY empnum) rn FROM xxc_contact one)

    3 WHERE phone = rn

    4.

    EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE

    ---------- -------------------- ---------- ---------- ----------

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    Kind regards

    Lalit

  • How to filter the records that contains the Spanish character?

    Hello

    I had an obligation to always records based on the Spanish character.

    Kindly guide me for below.

    To filter the records that contains Spanish characters?

    For example, I had a value in the column name as 'Sureshn '.

    My query should return the above folder that contains the Spanish character "N".

    Please do the necessary help / advice on that.

    Thank you
    Orahar

    I don't know what you want, because if you want a? ¢ Analysys and Sureshn, then my previous query is sufficient. However, maybe something like that.

    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH Sample_Data AS (SELECT 'â?¢ Analysys' str FROM DUAL UNION ALL
      2     SELECT 'SureshÑ' str FROM DUAL UNION ALL
      3     SELECT 'ABCD' str FROM DUAL UNION ALL
      4     SELECT 'WXYZ' str FROM DUAL UNION ALL
      5     SELECT 'Saubhik' str FROM DUAL
      6     )
      7     SELECT str AS "Contains other than English" from Sample_Data
      8*    WHERE REGEXP_LIKE(str,'[^[a-z,A-Z,0-9]]*')
    SQL> /
    
    Contains other
    --------------
    â?¢ Analysys
    SureshÑ
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH Sample_Data AS (SELECT 'â?¢ Analysys' str FROM DUAL UNION ALL
      2     SELECT 'SureshÑ' str FROM DUAL UNION ALL
      3     SELECT 'ABCD' str FROM DUAL UNION ALL
      4     SELECT 'WXYZ' str FROM DUAL UNION ALL
      5     SELECT 'Saubhik' str FROM DUAL
      6     )
      7     SELECT str AS "Contains English" from Sample_Data
      8*    WHERE NOT REGEXP_LIKE(str,'[^[a-z,A-Z,0-9]]*')
    SQL> /
    
    Contains Engli
    --------------
    ABCD
    WXYZ
    Saubhik
    
  • Dynamic SQL with in bulk in the record type

    Oracle 10.2 g

    I received this Tom

    [http://asktom.oracle.com/pls/apex/f?p=100:11:0:NO:]

    I'm able to do this without dynamic SQL, but my requirement is to do it in dynamic SQL
     create table t1 ( x int, y int );
    
     insert into t1 select rownum, rownum+1 from all_users where rownum <= 5;
    
     create table t2 ( x int, y int, z int );
    
     declare
                type array is table of t1%rowtype;
                l_data array;
        begin
                select * bulk collect into l_data from t1;
      
                forall i in 1 .. l_data.count
                
                       execute immediate 'insert into (select x, y from t2) values :x' using l_data(i);
        end;
     
    Error at line 1
    ORA-06550: line 9, column 90:
    PLS-00457: expressions have to be of SQL types
    ORA-06550: line 9, column 20:
    PL/SQL: Statement ignored
    There is a work around in 11g, but can we do something in 10g?



    Thank you
    HESH.

    HESH wrote:

    but following does not.

    declare
    type array is table of t1%rowtype;
    l_data array;
    begin
    select * bulk collect into l_data from t1;
    
    forall i in 1 .. l_data.count
    
    execute immediate 'insert into (select x, y from t2) values :x' using l_data(i);
    end;
    

    I want just a dynamic SQL code for the insert with FORALL statement would adopt as well as collections.

    Doesn't make much sense.

    Extract you the data from the SQL engine in the table of the record type. If the output data that cursor SQL must be read in the SQL engine and copied into the memory of PL/SQL engine.

    Then, you send that VERY SAME DATA back to the SQL engine to be used by a SQL insert cursor.

    Where is the logic behind the extraction of data from SQL in a PL/SQL table structure and then push this same structure table on the SQL engine database? What is the purpose to send data on a detour of underperforming and non-scalale through the PL/SQL engine?

    You have any justification (technical or functional wise) to back up this absurd approach?

    Why this can be achieved using a single SQL cursor that does both the choice (extraction) and (in bulk) insertion - using the plain old INSERT... SELECT structure?

    And if the insert is variable, then what? Create a dynamic INSERT... SELECT cursor and execute it (using bind values). This simple... Right?

  • Production PL/SQL query: can not find the error

    I have a PL/SQL which produces a query for me, which is used to fill out a report. I use this to supply a filter/search form. Since I want to only filter using xxx movies WHERE = yyy when yyy actually has something else NULL, I use a PL/SQL script in the query I need to produce. However, it does not work as expected and I can't understand why. Here is my code:
    DECLARE
      query VARCHAR(1000);
    BEGIN
      query := 'SELECT * FROM F_OBJEKTE WHERE 1=1 ';
      IF :P15_REGION != null THEN
        query := query || 'AND REGION = :P15_REGION ';
      END IF; 
      RETURN query;
    END;
    However, the report still contains all lines, as if P15_REGION has not been defined - and so I guess that the script never enters the IF part. Everyone around who can enlighten me, why it is?

    Just another little thing: is there a way I can print debugging messages I see when I press the "Debug" button on the lower bar of APEX? It would help a lot of debugging such PL/SQL functions.

    Try changing

    IF: P15_REGION! = null THEN

    TO

    IF: P15_REGION is not null THEN

  • SQL query as a filter in OBIEE

    I have a list of student_ID in a table (say A) and its subset in another table (table B)
    I want a filter so that only the student_ID in table A that are not in table B are selected.

    I'm selecting operator "not equal to / is not" of the student_id in table A and choose the option to SQL query to add value.

    Select distinct student_id from DatabaseName.B

    His does not work. His error after a large number of minor changes.

    Can you help how to solve this problem

    Try something like
    http://www.cool-bi.com/tweaks/JoinsinAnswers.php

    Use not exists or not instead of join.

    If brand aid

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

  • SQL query for data of the quarter... Help, please

    Dear Experts,

    Please help with this query...

    I have data as below:

    YearQuarterMRRMORR %
    -------------------
    20121ST QUARTER10
    Q230
    Q350
    Q460
    20131ST QUARTER20
    Q230

    Now I need to caluclate MORR % as column values below

    for 2012 T2 MRR % = (Q2MRR-Q1MRR) / (30-10) Q1 * 100 / 10 * 100

    for 2012, T3 MRR % = (Q4MRR-Q3MRR) / Q2 * 100

    for 2012 T4 MRR % = (Q1MRR-Q4MRR) / Q1 * 100 here q1 2013 and the 4th quarter of 2012...

    like this he wll go...

    Please help with me query calculate values in the column % MRR.

    Best regards

    ASP.

    Maybe NOT TESTED! No database at your fingertips

    Select the year, quarter, mrr,.

    ratio_to_report (q_mrr) on pct_mrr (partition by order of the year by quarter)

    (select the year, quarter, mrr,)

    MRR - lag (mrr, 1, 0) on q_mrr (partition by order of the year by quarter)

    t

    )

    Concerning

    Etbin

  • What is the best way to filter the records displayed in a DataGrid?

    Hi all

    I have a DataGrid that I use to show the records to a user.  I want to give them a few boxes to filter the different criteria.  For example, "hide/show has fallen members', ' see life only members", etc..

    My first thought was to attach an event listener that fires each time that a checkbox is checked/unchecked.  In addition, there an ArrayCollection 'original' collection that contains all of the records.  Each time a checkbox is checked or unchecked, loop then on the 'original' ArrayCollection collection, creating a new collection ArrayCollection that has only the records you want, and then you bind the DataGrid to whom.

    What is the right way to go on this subject?

    -Josh

    Instead of creating a new collection of arraycollection, use the FilterFunction function on the original arraycollection collection.

    I have a simple component on the exchange of Flex that allows to filter out people based on text matching

    http://www.Adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&EXTID=1414018

    You should be able to copy the logic and apply it to the boxes.

    Thank you

    Vackar

  • Having a problem with the trigger. (need help)

    Hi all

    I m totally new to the PL/SQL... hope someone can help me with this...

    I am now using the trigger to block insertion in the 'attendance99' table when records reach the maximum limit and insert the record in the table «waiting_list»
    The problem I encounter is using RAISE_APPLICATION_ERROR, it will block the insertion at the table "waiting_list" as well...
    I try to only use the DBMS_OUTPUT. Put_line instead, but end by > > > inserting record in the table 'presences' so many tables "waiting_list.



    -------------------------------------------------------------
    CREATE OR REPLACE TRIGGER trig_attendance
    Before Insert on attendance99
    Referring again like new
    for each line
    DECLARE
    maxstud NUMBER (2);
    currstud NUMBER (2);
    Begin
    SELECT COUNT (*) INTO currstud FROM attendance99 WHERE offering_id =:New.offering_id;
    SELECT max_no_students INTO maxstud to offer WHERE the offering_id =:New.offering_id;
    IF currstud > = maxstud
    THEN
    insert_waitinglist (: new .offering_id,: New.student_id,: New.evaluation,: New.amount_paid);
    RAISE_APPLICATION_ERROR (-20500, ' sorry, this offering ID has reach maximum students, you will be placed in queue! ");
    END IF;
    END;
    /
    ---------------------------------------------

    CREATE OR REPLACE PROCEDURE insert_waitinglist
    (v_offeringid IN waiting_list.offering_id%TYPE,
    v_studentid IN waiting_list.student_id%TYPE,
    v_evaluation IN waiting_list.evaluation%TYPE,
    v_amountpaid IN waiting_list.amount_paid%TYPE)
    IS
    BEGIN

    INSERT INTO waiting_list (student_id, assessment, offering_id, amount_paid)
    VALUES (v_offeringid, v_studentid, v_evaluation, v_amountpaid);
    END insert_waitinglist;
    /
    -----------------------------------------------

    Hello

    Try this:

    CREATE OR REPLACE PROCEDURE insert_waitinglist(v_offeringid IN waiting_list.offering_id%TYPE,
                                                   v_studentid  IN waiting_list.student_id%TYPE,
                                                   v_evaluation IN waiting_list.evaluation%TYPE,
                                                   v_amountpaid IN waiting_list.amount_paid%TYPE) IS
        PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    
        INSERT INTO waiting_list
            (offering_id,
             student_id,
             evaluation,
             amount_paid)
        VALUES
            (v_offeringid,
             v_studentid,
             v_evaluation,
             v_amountpaid);
    
        COMMIT;
    END insert_waitinglist;
    /
    

    Kind regards

    Published by: Walter Fernández on April 15, 2009 10:10 - missing ';', sorry

  • 'Use the cartridges SETUP' error on the printer, need help!

    I bought the printer last year in the months of August and after 6 months of use, it started having problems printing wireless. I always had to use USB to print from my laptop so I was recommended by people in this forum to reset my printer to the factory.

    I have reset several times and nothing worked, so I was advised to do so by using the Cancel button and the middle button that reset the printer. Now the problem is it says "Cartridges use SETUP" and my printer is out of warranty, it expired last month. I'm really confused about what to do. I am a student and I still have the print job and I can't afford a new printer. Calling support has no idea what to do and email support does not because of my warranty as you exhale.

    My printer is a HP Deskjet printer Wireless 3070. Product number is CQ191B.

    I really need help has begun the new year of college and I have a lot of missions to print.

    Hi ExPLOiT786

    Dragon-fur asked me to chime in with this. I will send you a private message on this in order to proceed.

    Ciara

  • I forgot the password need HELP

    I forgot my password for parental control and need to unlock them to install the new modem software.  Need HELP.

    http://support.Microsoft.com/default.aspx/KB/189126

    "Microsoft's strategy concerning lost or forgotten passwords"

    Microsoft cannot help you recover the passwords of the files and Microsoft who are lost or forgotten product features.

    Mick Murphy - Microsoft partner

  • Difference between the static SQL query and dynamic SQL query.

    Hello

    Please explain the fundamental difference between static and dynamic sql queries. Please explain for example.

    Static: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/static.htm
    Dynamics: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm

  • SQL query: only the numbers in the line of the somme - need help

    Pls see data below. I want to display only 8 lines and lines of BRH NCC should be merged and displayed as - BRH 98 2 instead of 2 rows. The rest of the lines must remain as it is. Help, please.


    NCC SERVICES MANUFACTURING
    ASL 138 NA
    BRH 98 NA
    BRH NA 2
    C10000 NA 0
    C40000 NA 0
    DAO NA 10
    E10000 NA 0
    I10000 NA 0
    M10000 NA 0

    Published by: auxilia on November 7th, 2009 06:25
    with t as (
               select 'ASL' ccn,'138' services,'NA' manufacturing from dual union all
               select 'BRH','98','NA' from dual union all
               select 'BRH','NA','2' from dual union all
               select 'C10000','NA','0' from dual union all
               select 'C40000','NA','0' from dual union all
               select 'DAO','NA','10' from dual union all
               select 'E10000','NA','0' from dual union all
               select 'I10000','NA','0' from dual union all
               select 'M10000','NA','0' from dual
              )
    select  ccn,
            nvl(max(case services when 'NA' then null else services end),'NA') services,
            nvl(max(case manufacturing when 'NA' then null else manufacturing end),'NA') manufacturing
      from  t
      group by ccn
    /
    
    CCN    SERVICES             MANUFACTURING
    ------ -------------------- --------------------
    E10000 NA                   0
    C10000 NA                   0
    BRH    98                   2
    M10000 NA                   0
    C40000 NA                   0
    ASL    138                  NA
    I10000 NA                   0
    DAO    NA                   10
    
    8 rows selected.
    
    SQL>   
    

    SY.

    Published by: Solomon Yakobson on November 7th, 2009 06:46

  • SQL query for roll up the amounts from more down to the highest level

    with data (select child 'C', 'P' as a parent, 11 amount of double

    the Union all select 'C1', 'C',-2 double

    Union all select 'C2', 'C', 3 double

    the Union all select 'C3', 'C',-8 double

    Union all select 'C4', 'C', 10 double

    Union all select 'C11', 'C1', 7 double

    the Union of all select them 'C12', 'C1', double 12

    Union all select "C21", "C2", 5 double

    Union all select "C22", "C2", 9 double

    Union all select 'C31', 'C3', 6 double

    the Union all select 'C32', 'C3',-4 double

    the Union all select 'C41', 'C4',-3 double

    the Union of all select them "C42', 'C4' 13 doubles

    the Union of all select them "C111", "C11", 16 doubles

    Union all select 'C121","C12", 8 double

    ) Select * from given by 2

    Hi Experts,

    I have the following table with the child-parent relationship which I would like to roll up from a lower to a higher level. The problem here is that I'm moving the level I should replace the amount for a parent with the overall value of his children and grand total aggregate amount should be c

    For example; In the example given the c111 data roll up to c11 as 16 (Please note: the amount for c11 is 7 should not be added to 16 rather replaced by 16) that more should roll up to c1.

    That means c1 = c11c12; c11 = c111 = 16 Yes, c1 = 16instread 12 16712.

    Since it is an intermediate table, I don't have any control over how many levels it can contain.

    So dynamically, I need a rollup query and group the amount of a lower to a higher level from the bottom.

    Is this possible? I look forward to any help. Thanks in advance.

    SQL > data
    () 2
    3. Select 'C' child, 'P' as a parent, 11 amount of double
    4 union all select 'C1', 'C',-2 double
    5 Union all select them 'C2', 'C', 3 double
    6 Union all select them 'C3', 'C',-8 double
    7 union all select 'C4', 'C', 10 double
    8 union all select 'C11', 'C1', the double 7
    9 Union all select 'C12', 'C1', 12 dual from
    all the 10 union select "C21", "C2", 5 double
    all the 11 union select "C22", "C2", 9 double
    12 union all select 'C31', 'C3', 6 double
    all the 13 union select 'C32', 'C3',-4 double
    14 union all select 'C41', 'C4',-3 double
    all the 15 union select 'C42', 'C4', 13 from dual
    all the 16 union select 'C111","C11", 16 of the double
    all the 17 union select 'C121","C12", 8 double
    18)
    19, data1
    20 in accordance with
    (21)
    22 Select parent
    23, child
    24, lpad ('-', (level 1) * 3, '-'). parent tree_structure
    25, amount
    26, case when connect_by_isleaf = 1 then amount 0 otherwise end amount_leaf
    27 data
    starting 28 with parent = 'P '.
    29 to connect
    30 per parent prior child =
    31)
    32 Select parent as a node
    33, tree_structure
    34, amount_sum
    35 of Data1
    model 36
    size 37 by
    (38)
    39 children
    40, parent
    41)
    42 measures
    (43)
    44 amount_leaf as the amount
    45, tree_structure
    46, 0 amount_sum
    47)
    automatic control of 48 rules
    (49)
    50 amount_sum [none, none] = amount [cv (), cv ()] + nvl (sum (amount_sum) [all cv (child)], 0)
    (51);

    ŒIL TREE_STRUCTURE AMOUNT_SUM BLINK
    --- ------------------------- ----------


    P   P                                 50
    C   ---C                              24
    C1  ------C1                          16
    C11 ---------C11                      16
    C1  ------C1                           8
    C12 ---------C12                       8
    C   ---C                              14
    C2  ------C2                           5
    C2  ------C2                           9
    C   ---C                               2
    C3  ------C3                           6
    C3  ------C3                          -4
    C   ---C                              10
    C4  ------C4                          -3
    C4  ------C4                          13

    15 selected lines.

Maybe you are looking for