Please help to write a complex query "select".

Hello

I am trying to write a query that retrieves information about attachments in HP ALM by referring to TestInstances, TestRun and TestSteps tables. For those who do not know HP ALM...

I'm describing the structure of data in these tables (the names of tables and fields are changed for easy understanding).

> > 1. In the "TestInstances" table key fields are I_InstanceID, I_HasAttachments and I_TestSetID

1.1 I_InstanceID is the primary key for this table

> > 2. Key in the table "TestRuns" fields are R_RunID, R_InstanceID, R_RunTime and R_HasAttachments

2.1 R_RunID is the primary key for this table

2.2 R_InstanceID is a foreign key to I_InstanceID in the TestInstances table

2.3 all I_InstanceID in the TestInstances table may not have an entry in the table TestRuns

2.4 an I_InstanceID in TestInstances can have multiple entries in the table TestRuns with different R_RunID

> > 3. In the "TestSteps" table key fields are S_StepID, S_RunID and S_HasAttachments

3.1 S_StepID is the primary key for this table

3.2 S_RunID is a foreign key to R_RunID in the TestRuns table

3.3 all R_RunID in the TestRuns table may not have an entry in the TestSteps table

3.4 a R_RunID in TestRuns can have multiple entries in the table TestSteps with different S_StepID

Entry to the query I want to write is a set of I_TestSetID in the TestInstances table (which I already have)

The desired query output is -.

1. all I_InstanceID have the values as shown in the entry I_TestSetID

2 I_HasAttachments corresponding to I_InstanceID

3. Earl of R_RunID against each I_InstanceID (may be 0 or a positive integer)

4. only the last R_RunID corresponding to each I_InstanceID (later are using MAX (R_RunID) GROUP BY I_InstanceID)

5 R_HasAttachment value of last R_RunID

6 R_RunTime last R_RunID value

7. County of S_StepID against each R_RunID (may be 0 or a positive integer)

8. County of S_HasAttachment against each R_RunID (may be 0 or a positive integer and may differ from the County of S_StepID)

Friends, could one of you give it a try and help out me?

Thanks in advance!

PS: This had been driving me crazy for 3 days. I'm not able to get unique entries and entries for which references to the TestRun and TestStep tables are empty.

Try the bottom of correlated subquery

SELECT i_instanceid,

i_hasattachments,

(SELECT COUNT (R_RunID)

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid) cnt_runid;

(SELECT MAX (R_RunID)

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid) cnt_latestrunid;

(SELECT I_HasAttachments

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid

AND tr.r_runid = (SELECT MAX (R_RunID)

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid)) R_HasAttachments;

(SELECT R_RunTime

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid

AND tr.r_runid = (SELECT MAX (R_RunID)

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid)) R_RunTime;

(SELECT COUNT (S_StepID)

OF TestSteps ts

WHERE the ts. S_RunID = (SELECT MAX (R_RunID)

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid)) cnt_stepid;

(SELECT COUNT (S_HasAttachments)

OF TestSteps ts

WHERE the ts. S_RunID = (SELECT MAX (R_RunID)

OF TestRuns tr

WHERE tr.r_instanceid = ti.i_instanceid)

AND S_HasAttachments = 'Y') cnt_SHasAttachment

OF ti TestInstances

WHERE I_TestSetID IN (1190,1191,1192,1194,1195);

Tags: Database

Similar Questions

  • Please help me write this SQL query...

    Hi everyone,
    
    Please help me in this query.
    A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and
    if they have (M and D) i need to select type M,and if they have only type D i have to select that.
    For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag)
    
    Patient table
    =============
    
    Patient_id          First_name    last_name
    
    1                   sanjay        kumar
    2                   ajay          singh
    3                   Mike          John
    
    
    Adress table
    ============
    
    address_id       patient_id       adresss       city       type       startdate        enddate      valid_flg
    
    1                   1             6222         dsadsa           P          01/01/2007       01/01/2010
    2                   1             63333        dsad             M          01/02/2006       01/01/2007      N
    3                   1             64564         fdf              M          01/01/2008       07/01/2009      
    4                   1             654757       fsdfsa          D          01/02/2008       09/10/2009  
    5                   2             fsdfsd       fsdfsd            M          01/03/2007       09/10/2009   
    6                   2             jhkjk        dsad              D          01/01/2007       10/10/2010   
    7                   3             asfd         sfds               D          01/02/2008       10/10/2009      
    
    
    output
    =====
    
    1        sanjay       kumar            6222       dsadsa      P          01/01/2007        01/01/2010     
    2        ajay         singh            fsdfsd     fsdfsd       M          01/03/2007        09/10/2009 
    3        mike         john              asfd       sfds        D          01/02/2008        10/10/2009
    Thanks in advance
    Phani

    Hello, Fabienne,.

    This race for you (twisted code of Sarma):

    SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
     FROM (
      SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
                 ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                          WHEN  'M' THEN 2
                                                                          WHEN  'D' THEN 3
                                                                        END) rn
        FROM  patient p
        JOIN  address a ON (p.patient_id = a.patient_id )
       WHERE NVL(valid_flg, 'X') != 'N'
         AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
         )
    WHERE rn = 1; 
    

    Edit, currently in the trial:

    With Patient AS (
    SELECT 1  Patient_id , 'sanjay' First_name, 'kumar'  last_name FROM DUAL UNION ALL
    SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL
    SELECT 3, 'Mike', 'John' FROM DUAL),
    Address AS (
    SELECT 1   address_id, 1  patient_id, '6222'    address, 'dsadsa'   city, 'P'  type, to_date('01/01/2007', 'DD/MM/YYYY')  startdate, to_date('01/01/2010', 'DD/MM/YYYY')  enddate, NULL  valid_flg FROM DUAL UNION ALL
    SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'),  ' N'  FROM DUAL UNION ALL
    SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
    SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
    SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
    SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
    SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL)
    -- end test data
     SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
     FROM (
      SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
                 ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                          WHEN  'M' THEN 2
                                                                          WHEN  'D' THEN 3
                                                                        END) rn
        FROM  patient p
        JOIN  address a ON (p.patient_id = a.patient_id )
       WHERE NVL(valid_flg, 'X') != 'N'
         AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
         )
    WHERE rn = 1; 
    
    PATIENT_ID FIRST_ LAST_ ADDRESS CITY   TY STARTDATE ENDDATE
    ---------- ------ ----- ------- ------ -- --------- ---------
             1 sanjay kumar 6222    dsadsa P  01-JAN-07 01-JAN-10
             2 ajay   singh fsdfsd  fsdfsd M  01-MAR-07 09-OCT-09
             3 Mike   John  asfd     sfds  D 01-FEB-08 10-OCT-09
    
  • Need help to write a sub query

    Our environment - Oracle 10 g

    Hi all
    Need help to write a sub query to reach him here are examples of data using which iam trying to replace the value column in the table based on two other columns in the same table

    Examples of data

    ClaimNo flag LineNo Procedurecode
    100 01 N MN4567
    100 02 Y 7863
    100 03 N MN8976
    100 04 Y 9000
    101 01 Y 8954
    101 02 N MN6754
    101 03 N MN7654
    101 04 Y 8976
    102 01 Y 1234
    102 02 Y 2345
    102 03 Y 3456
    102 03 Y 4567

    Each column of ClaimNo has several rows of data. But if column procedurecode for a claimNo starts with MN then all values associated with the claimno for the flag column should replace N

    If the data must become like below

    ClaimNo flag LineNo Procedurecode
    100 01 N MN4567
    100 02 N 7863
    100 03 N MN8976
    100 04 N 9000
    101 01 N 8954
    101 02 N MN6754
    101 03 N MN7654
    101 04 N 8976
    102 01 Y 1234
    102 02 Y 2345
    102 03 Y 3456
    102 03 Y 4567


    Thank you

    See the example:

    with t as (
                  select 100 ClaimNo, '01' LineNo, 'N' Flag, 'MN4567' Procedurecode from dual
        union all select 100, '02', 'Y', '7863' from dual
        union all select 100, '03', 'N', 'MN8976' from dual
        union all select 100, '04', 'Y', '9000' from dual
        union all select 101, '01', 'Y', '8954' from dual
        union all select 101, '02', 'N', 'MN6754' from dual
        union all select 101, '03', 'N', 'MN7654' from dual
        union all select 101, '04', 'Y', '8976' from dual
        union all select 102, '01', 'Y', '1234' from dual
        union all select 102, '02', 'Y', '2345' from dual
        union all select 102, '03', 'Y', '3456' from dual
        union all select 102, '03', 'Y', '4567' from dual
    )
    select
        claimno,
        lineno,
        flag,
        case
          when count(decode(substr(procedurecode,1,2),'MN',1)) over(partition by claimno)>0
            then 'N'
          else flag
        end new_flag,
        procedurecode
    from t
    

    Kind regards
    Sayan M.

  • Need help to write a SQL query complex

    I have the source tabe as below

    -> SOURCE_TABLE
    NAME     CUST_ID     SVC_ST_DT     SVC_END_DT 
    TOM        1               31/08/2009      23/03/2011 
    DOCK       2               01/01/2004      31/05/2010 
    HARRY      3               28/02/2007      31/12/2009 
    I want to load as target table below
    -> TARGET_TABLE
    NAME     CUST_ID                     SVC_ST_DT      SVC_END_DT 
    TOM      1           31/08/2009      31/12/2009 
    TOM      1           01/01/2010      31/12/2010 
    TOM      1           01/01/2011      23/03/2011 
    DOCK      2           01/01/2004      31/12/2004 
    DOCK      2           01/01/2005      31/12/2005 
    DOCK      2           01/01/2006      31/12/2006 
    DOCK      2           01/01/2007      31/12/2007 
    DOCK      2           01/01/2008      31/12/2008 
    DOCK      2           01/01/2009      31/12/2009 
    DOCK      2           01/01/2010      31/05/2010 
    HARRY      3           28/02/2007      31/12/2007 
    HARRY      3           01/01/2008      31/12/2008 
    HARRY      3           01/01/2009      31/12/2009 
    Is it possible to write a SQL query that returns the data in the same way above the target table.

    Published by: AChatterjee on April 30, 2012 07:14

    Published by: AChatterjee on April 30, 2012 07:14

    Or like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'TOM' as NAME, 1 as CUST_ID, date '2009-08-31' as SVC_ST_DT, date '2011-03-23' as SVC_END_DT from dual union all
      2             select 'DOCK', 2, date '2004-01-01', date '2010-05-31' from dual union all
      3             select 'HARRY', 3, date '2007-02-28', date '2009-12-31' from dual)
      4  --
      5  -- end of test data
      6  --
      7  select name, cust_id, svc_st_dt, svc_end_dt
      8  from (
      9        select name
     10              ,cust_id
     11              ,greatest(svc_st_dt, add_months(trunc(svc_st_dt,'YYYY'),yr*12)) as svc_st_dt
     12              ,least(svc_end_dt, add_months(trunc(svc_st_dt,'YYYY'),(yr+1)*12)-1) as svc_end_dt
     13        from t
     14             cross join (select rownum-1 as yr
     15                         from   dual
     16                         connect by rownum <= (select extract(year from max(svc_end_dt)) - extract(year from min(svc_st_dt)) + 1 from t)
     17                        )
     18       )
     19  where svc_st_dt <= svc_end_dt
     20* order by 2, 3
    SQL> /
    
    NAME     CUST_ID SVC_ST_DT            SVC_END_DT
    ----- ---------- -------------------- --------------------
    TOM            1 31-AUG-2009 00:00:00 31-DEC-2009 00:00:00
    TOM            1 01-JAN-2010 00:00:00 31-DEC-2010 00:00:00
    TOM            1 01-JAN-2011 00:00:00 23-MAR-2011 00:00:00
    DOCK           2 01-JAN-2004 00:00:00 31-DEC-2004 00:00:00
    DOCK           2 01-JAN-2005 00:00:00 31-DEC-2005 00:00:00
    DOCK           2 01-JAN-2006 00:00:00 31-DEC-2006 00:00:00
    DOCK           2 01-JAN-2007 00:00:00 31-DEC-2007 00:00:00
    DOCK           2 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    DOCK           2 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    DOCK           2 01-JAN-2010 00:00:00 31-MAY-2010 00:00:00
    HARRY          3 28-FEB-2007 00:00:00 31-DEC-2007 00:00:00
    HARRY          3 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    HARRY          3 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    
    13 rows selected.
    
  • Need help to write the SQL query

    Hello
    Please help me to write a query. My requirement is as below.

    Hello
    I have a table say XYZ in the following format.

    product_id local min_order_quntity
    ========================================
    1 en 10
    1 ch 10
    2 en 20
    2 ch 20
    3 en 30
    3 ch 30
    4 en 40
    4 NC 10

    Now I want to find the product_id where min_order_quantity is different for cn and locale

    now I want the result of the following

    product_id local min_order_quantity
    =============================================
    4          en          40
    4 ch 10

    This is different for local in and cn for product_id 4 min_order_quantity

    min_order_quantity should be the same for both the locale(en,ch) for any product_id.

    I want to find the product_id where min_order_quantity is different for ch and fr local

    Thank you..

    Hello

    This query should do the job

    select * from xyz t1
    where exists ( select 1 from xyz t2 where t2.product_id = t1.product_id and
                   t2.locale != t1.locale and t2.min_order_quantity != t1.min_order_quantity );
    

    See you soon

  • Please help me with this SQL query

    I'm practicing of SQL queries and met one involving the extraction of data from 3 different tables.

    The three paintings are as below

    < pre >
    Country
    Location_id country
    LOC1 Spain
    loc2 England
    LOC3 Spain
    loc4 USA
    loc5 Italy
    loc6 USA
    loc7 USA
    < / pre >
    < pre >


    User
    user_id location_id
    loc1 U1
    loc1 U2
    loc2 U3
    loc2 U4
    loc1 U5
    U6 loc3
    < / pre >
    < pre >


    Publish
    user_id post_id
    P1 u1
    P2 u1
    U2 P3
    P4 u3
    P5 u1
    P6 u2
    < / pre >

    I am trying to write a SQL query - for each country of the users, showing the average number of positions

    I understand the logic behind all this that we must first consolidate all locations, and then the users in one country and then find the way to their positions.
    But, I'm having a difficulty to this format SQL. Could someone help me please with this request.

    Thank you.

    Select
    Country.Country,
    Count (*) Totalpostspercountry,
    Count (distinct post.user_id) Totaldistincuserspercountry,
    count (*) / count (distinct post.user_id) Avgpostsperuserbycountry
    Of
    countries, have, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    Country.country group

    The output is like this for your sample data - hope that's what you're looking for :)

    COUNTRY, TOTALPOSTSPERCOUNTRY, TOTALDISTINCUSERSPERCOUNTRY, AVGPOSTSPERUSERBYCOUNTRY
    In England, 1, 1, 1.
    Spain, 5, 2, 2.5.

  • Please help me write a query

    I have a table called claims and I want to know the lines that have the same application id and members
    with cert = 'MEMBER' and insert the date exceeds the other rows in the same claim and Member ID.

     Eg:
    
    
    
    Insert date             claim                    member Id        cert      
    7/17/2009               2009106                  1345678         1345678  
    8/8/2009                2009106                  1345678         MEMBER  
    
    12/11/2009              2009107            1345679         MEMBER
    12/14/2009          2009107                   1345679         1345679
    
    
    Expected row:
    
    7/17/2009               2009106                  1345678         1345678  
    8/8/2009                2009106                  1345678         MEMBER  
    Help, please.

    Hello

    Here's a way to do it:

    SELECT     *
    FROM     table_x
    WHERE     (claim, member_id) IN
         (
              SELECT       claim
              ,       member_id
              FROM       table_x
              GROUP BY  claim
              ,            member_id
              HAVING       MAX (insert_date) = MAX ( CASE
                                       WHEN  cert = 'MEMBER'
                                       THEN  insert_date
                                         END
                                    )
              AND       COUNT (*)          > 1       -- Unclear if you want this
         )
    ;
    

    If you want to post CREATE TABLE and INSERT for some samples statements, then I could test this.

    If the combination (claim, member_id, insert_date) is not unique, this will include groups where a row of 'MEMBER' links with no 'MEMBER' for the latest insert_date lines. If links are possible, but you only want to groups where the last row is a 'MEMBER', then you'll need another expression BOX.

  • Please help to write a query to get the result in a different format


    The Version of database: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0

    Table of scripts create script and data;

    CREATE TABLE test
    (
       col1   VARCHAR2 (2),
       col2   VARCHAR2 (2),
       col3   VARCHAR2 (2),
       col4   VARCHAR2 (2),
       col5   VARCHAR2 (2)
    );
    insert into test values('x','y','','','');
    insert into test values('x','','p','','');
    insert into test values('x','','q','','');
    insert into test values('x','','','t','');
    insert into test values('x','','','','s');
    

    select * from test;
     
    
    COL1COL2COL3COL4COL5
    xThere
    xp
    xq
    xt
    xs

    I need output like below:

    COL1COL2COL3COL4COL5
    xTherepts
    xq

    Each column is sorted alphabetically.

    Thank you
    Sam

    Hi, Sam,.

    Here's one way:

    WITH unpivoted_data AS

    (

    SELECT T.*

    ROW_NUMBER () OVER (PARTITION BY col

    ORDER BY val

    ) AS r_num

    OF the test

    UNPIVOT (val

    FOR the collar (col2, col3, col4 col5)

    ) t

    )

    SELECT col1, col2, col3, col4, col5 - or SELECT * to display r_num, too

    Of unpivoted_data

    PIVOT (MIN (val)

    FOR col IN ('COL2' AS col2

    'COL3' AS col3

    'COL4' AS col4

    "COL5" AS col5

    )

    )

    ORDER BY col1, r_num

    ;

    This does not imply that all but one of the (col2, col3, col4 col5) will be NULL on line any test.

  • Please help me to set a query that was so irritating... (test 2)

    I thank in advance for any help, you can provide or you the light can shine
    on that. I tried to work this problem for a few days
    and continue to run into a wall, so any help is appreciated more.

    Overview-

    We have a collection of sites. At each location, users can create
    checklists and assign ratings to the elements.

    Database model:
    CREATE TABLE RATINGS_DETAIL
    (
      RATING_ID           NUMBER(5),
      RATING_DESCRIPTION  VARCHAR2(30 BYTE)
    );
    
    CREATE TABLE ITEMS
    (
      ITEM_ID           NUMBER(5),
      ITEM_DESCRIPTION  VARCHAR2(1000 BYTE)
    );
    
    
    CREATE TABLE CHECKLIST_USERS
    (
      USER_ID    NUMBER(5),
      USER_NAME  VARCHAR2(32 BYTE)
    );
    
    CREATE TABLE CHECKLIST
    (
      CHECKLIST_ID           NUMBER(5),
      LOCATION_ID            NUMBER(5),
      CHECKLIST_DESCRIPTION  VARCHAR2(1000 BYTE),
      CHECKLIST_DATE         DATE,
      CHECKLIST_EXTERNAL     CHAR(1 BYTE)
    );
    
    CREATE TABLE CHECKLIST_ITEMS
    (
      ITEM_ID         NUMBER(5),
      CHECKLIST_ID    NUMBER(5),
      RATING_ID       NUMBER(5),
      RATING_USER_ID  NUMBER(5)
    );
    
    ALTER TABLE RATINGS_DETAIL ADD (CONSTRAINT RATINGS_DETAIL_PK PRIMARY KEY (RATING_ID));
    
    ALTER TABLE ITEMS ADD (CONSTRAINT ITEMS_PK PRIMARY KEY (ITEM_ID));
    
    ALTER TABLE CHECKLIST_USERS ADD (CONSTRAINT CHECKLIST_USERS_PK PRIMARY KEY (USER_ID));
    
    ALTER TABLE CHECKLIST ADD (CONSTRAINT CHECKLIST_PK PRIMARY KEY (CHECKLIST_ID));
    
    ALTER TABLE CHECKLIST_ITEMS ADD (CONSTRAINT CHECKLIST_ITEMS_PK PRIMARY KEY (ITEM_ID, CHECKLIST_ID));
    
    ALTER TABLE CHECKLIST_ITEMS ADD (
      CONSTRAINT CHLIST_ITEM_RATING_FK FOREIGN KEY (RATING_ID) REFERENCES RATINGS_DETAIL (RATING_ID),
      CONSTRAINT CHLIST_ITEM_USER_FK FOREIGN KEY (RATING_USER_ID) REFERENCES CHECKLIST_USERS (USER_ID),
      CONSTRAINT CHLIST_ITEMS_LIST_FK FOREIGN KEY (CHECKLIST_ID) REFERENCES CHECKLIST (CHECKLIST_ID),
      CONSTRAINT CHLIST_ITEMS_ITEM_FK FOREIGN KEY (ITEM_ID) REFERENCES ITEMS (ITEM_ID));
    And some data
    Insert into CHECKLIST
       (checklist_id, location_id, checklist_description, checklist_date, checklist_external)
     Values (1, 1, 'Internal List 1', TO_DATE('09/01/2011', 'MM/DD/YYYY'), 'N');
    Insert into CHECKLIST
       (checklist_id, location_id, checklist_description, checklist_date, checklist_external)
     Values (2, 1, 'External List 1', TO_DATE('05/01/2011', 'MM/DD/YYYY'), 'Y');
    Insert into CHECKLIST
       (checklist_id, location_id, checklist_description, checklist_date, checklist_external)
     Values (3, 1, 'External List 2', NULL, 'Y');
    Insert into CHECKLIST
       (checklist_id, location_id, checklist_description, checklist_date, checklist_external)
     Values (4, 1, 'External List 3', TO_DATE('08/01/2011', 'MM/DD/YYYY'), 'Y');
    Insert into CHECKLIST
       (checklist_id, location_id, checklist_description, checklist_date, checklist_external)
     Values (5, 1, 'External List 4', NULL, 'Y');
    Insert into CHECKLIST
       (checklist_id, location_id, checklist_description, checklist_date, checklist_external)
     Values (6, 2, 'Internal List 1 (loc 2)', TO_DATE('08/01/2011', 'MM/DD/YYYY'), 'N');
    COMMIT;
    
    
    Insert into ITEMS (item_id, item_description) Values   (1, 'Item 1');
    Insert into ITEMS (item_id, item_description) Values   (2, 'Item 2');
    Insert into ITEMS (item_id, item_description) Values   (3, 'Item 3');
    Insert into ITEMS (item_id, item_description) Values   (4, 'Item 4');
    Insert into ITEMS (item_id, item_description) Values   (5, 'Item 5');
    Insert into ITEMS (item_id, item_description) Values   (6, 'Item 6');
    Insert into ITEMS (item_id, item_description) Values   (7, 'Item 7');
    Insert into ITEMS (item_id, item_description) Values   (8, 'Item 8');
    Insert into ITEMS (item_id, item_description) Values   (9, 'Item 9');
    Insert into ITEMS (item_id, item_description) Values   (10, 'Item 10');
    COMMIT;
    
    
    Insert into RATINGS_DETAIL (rating_id, rating_description) Values (1, 'Low');
    Insert into RATINGS_DETAIL (rating_id, rating_description) Values (2, 'Med');
    Insert into RATINGS_DETAIL (rating_id, rating_description) Values (3, 'High');
    COMMIT;
    
    Insert into CHECKLIST_USERS (user_id, user_name) Values (1, 'Internal User');
    Insert into CHECKLIST_USERS (user_id, user_name) Values (2, 'External User');
    COMMIT;
    
    
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (1, 1, 1, 1);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (2, 1, NULL, NULL);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (3, 1, 1, NULL);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (4, 1, 3, 1);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (5, 1, 3, 1);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (8, 1, 2, 1);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (1, 2, NULL, NULL);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (2, 2, NULL, NULL);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (6, 2, 2, 2);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (7, 2, 1, 2);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (1, 3, NULL, NULL);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (8, 3, 2, 2);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (1, 4, 3, 2);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (6, 4, 1, 2);
    Insert into CHECKLIST_ITEMS (item_id, checklist_id, rating_id, rating_user_id)
               Values (8, 4, NULL, NULL);
    COMMIT;
    To get the items for a given list:
      1  SELECT CC.checklist_id, II.item_id, CHI.rating_id, RR.rating_description
      2    FROM checklist CC
      3    LEFT JOIN checklist_items CHI ON CC.checklist_id =CHI.checklist_id
      4    LEFT JOIN items II            ON CHI.item_id =II.item_id
      5    LEFT JOIN ratings_detail RR   ON CHI.rating_id =RR.rating_id
      6*  WHERE     CC.checklist_id =1
    SQL> /
    
    CHECKLIST_ID    ITEM_ID  RATING_ID RATING_DESCRIPTION
    ------------ ---------- ---------- ------------------
               1          3          1 Low
               1          1          1 Low
               1          8          2 Med
               1          5          3 High
               1          4          3 High
               1          2
    and
      
      1  SELECT CC.checklist_id, II.item_id, CHI.rating_id, RR.rating_description
      2    FROM checklist CC
      3    LEFT JOIN checklist_items CHI ON CC.checklist_id =CHI.checklist_id
      4    LEFT JOIN items II            ON CHI.item_id =II.item_id
      5    LEFT JOIN ratings_detail RR   ON CHI.rating_id =RR.rating_id
      6*  WHERE     CC.checklist_id =4
    SQL> /
    
    CHECKLIST_ID    ITEM_ID  RATING_ID RATING_DESCRIPTION
    ------------ ---------- ---------- ------------------------------
               4          1          3 High
               4          6          1 Low
               4          8  
      
      
    Now the problem:

    For a given location, there may be multiple lists - 1 list of audit 'Internal' and any number of checklists "External" (including 0). They may, but have not, share items.

    It should pull up a query that joins the list of internal control with the most recent list of external audit. And there manage if there is no list of external control.

    So far, the best I've been able to understand is to make each separate list and then try to merge the results later, but it's not effective for hundreds of possible objects we need to "Preview" in several places and find all their results which would be thousands of results.


    So, I want a single query to retrieve the data if possible. I can make a separate request for internal identification numbers and a list of corresponding external audit.


    I need to produce something like this:
      1  SELECT checklist_id AS INTERNAL_ID FROM checklist
      2* WHERE checklist_external ='N' AND location_id =1
    SQL> /
    
    INTERNAL_ID
    -----------
              1
               
      1  SELECT     EE.checklist_id AS EXTERNAL_ID
      2    FROM     checklist EE
      3   WHERE  EE.checklist_external ='Y'
      4     AND  EE.checklist_date =(SELECT  max(EE2.checklist_date)
      5                           FROM  checklist EE2
      6                          WHERE  EE2.checklist_external ='Y'
      7                                 AND  EE2.location_id =EE.location_id)
      8*   AND      EE.location_id =1
    SQL> /
    
    EXTERNAL_ID
    -----------
              4
    What I want is a result like this
    INTER  EXTER  ITEM_ID  I_RATING  E_RATING
    ----- ------ -------- ---------- ---------
        1      4        1 Low        High
        1               2
        1               3 Low
        1               4 High
        1               5 High
               4        6            Low
        1      4        8 Med
        
      1  SELECT     CC1.checklist_id AS INTER,
      2             CC2.checklist_id AS EXTER,
      3             II.item_id,
      4             RD1.rating_description AS I_rating,
      5             RD2.rating_description AS E_rating
      6    FROM     items II
      7    JOIN     checklist_items CHI1 ON II.item_id =CHI1.item_id
      8    JOIN     ratings_detail RD1 ON CHI1.rating_id =RD1.rating_id
      9    JOIN     checklist CC1 ON CHI1.checklist_id =CC1.checklist_id
     10                                     AND CHI1.checklist_id =1
     11    JOIN     checklist_items CHI2 ON II.item_id =CHI2.item_id
     12    JOIN     ratings_detail RD2 ON CHI2.rating_id =RD2.rating_id
     13    JOIN     checklist CC2 ON CHI2.checklist_id =CC2.checklist_id
     14*                                    AND CHI2.checklist_id =4
     15  /
    
         INTER      EXTER    ITEM_ID I_RATING      E_RATING
    ---------- ---------- ---------- ------------- --------------
             1          4          1 Low           High
    Addition of LEFT joins on the right does not work and I can't find a combination that works... what Miss me?
  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

  • Please help me fix this SQL query...

    Hi, please consider following:
    create table test (col varchar2 (255))
    insert into test values ("TERM").
    Insert test values ("VOLUME");

    Select the test pass where pass in ('TIME', 'VOLUME');
    This property returns the rows.

    but my input string is a comma-separated list:
    DURATION, VOLUME

    so I try
    Select the test pass where col to (replace (' DURATION, VOLUME, ',' "'," '));
    but no result. Or:
    Select the test pass where col in ("' | replace (' DURATION, VOLUME, ','" ', "') |") ') ;

    However
    Select "' | Replace (' DURATION, VOLUME, ',' "'," ') | " ' the double
    gives "DURATION", "VOLUME".

    then why does it work?

    hope you can help. Thank you

    convert stringlist in lines and then use in the clause...

    SELECT col
       FROM test
      WHERE col IN
      (SELECT    *
         FROM
        (SELECT TRIM( SUBSTR ( txt , INSTR (txt, ',', 1, level ) + 1 , INSTR (txt, ',', 1, level+1 ) - INSTR (txt, ',', 1, level) -1 ) ) AS token
           FROM
          ( SELECT ','||'DURATION,VOLUME'||',' AS txt FROM dual
          )
          CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1
        )
      )
    

    Ravi Kumar

  • need help to write a conditional query recordset

    I have two fields or not in the database. VeteranMarker and VeteranNoMarker. Answering one can be Y or N.
    I want to write a statement for my detail page where there is a label "veteran? If VeteranMarker or VeteranNoMarker has a Y in the database, then I want to display "YES" next to the label of "veteran? If neither has a Y, then I want to say 'NO '.

    The recordset is called DetailRS1, the fields would be so (I think) DetailRS1.VeteranMarker and DetailRS1.VeteranNoMarker.

    I have no idea how to write a conditional statement to achieve this.

    Thanks in advance,
    Miriam

    I think I have it solved. Here is the code, and it seems to work. If this is correct, I hope it can help someone else too.

  • Please help with the oracle text and select for each word in the sentence

    Hello

    I have a problem with a query which NEEDS to be done in SQL (not pl/sql in the stored procedure):

    Suppose that a phrase such as "Church of snowboarding."

    Can I divide this by using:
    Select regexp_substr ('church snowboard', ' [^] +', 1, level) word
    of the double
    connect regexp_substr ('church snowboard', ' [^] +', 1, level) is not NULL)

    now I have words 'showboard' and 'Church '.

    So far so good.

    Now I need for each of these words, to create a list of unique IDS collected using text oracle contains the query as follows: (pseudocode)
    for SPLIT.word in "snowboarding", "Church".
    SELECT SCORE (1) NIVEAU_RECHERCHE,
    NO_MATRC,
    NO_NOM_
    OF GR_OT_NOM_ASSJT
    WHERE CONTAINS (name, SPLIT.word, 1) > 0
    UNION
    SELECT SCORE (1) NIVEAU_RECHERCHE,
    NO_MATRC,
    NO_NOM_
    OF GR_OT_NOM_ASSJT
    WHERE CONTAINS (name, ' SYN('||)) SPLIT.word: ', GR_THESAURUS)', 1) > 0
    UNION
    SELECT 100 AS NIVEAU_RECHERCHE,
    NO_MATRC,
    NO_NOM_
    OF GR_OT_NOM_ASSJT
    WHERE NAME LIKE '% "| SPLIT.word | '%'

    so of course I have to untangle this UNION to remove duplicates

    Anyone here sees a way out of my situation? A way to make the loop in a select (use with and such) then
    Just add a select distinct NO_MATRC, NO_NOM_ from)

    I tried, but I'm out of ideas so I thought that some guru here might have the answer ;)

    Thanks in advance for any advice

    See you soon

    You might end up with something like the XML below, ideally as binding in the query.

    SELECT SCORE (1) NIVEAU_RECHERCHE,
    NO_MATRC,
    NO_NOM_
    OF GR_OT_NOM_ASSJT
    WHERE CONTAINS (name, e
    Church of snowboard

    transform ((JETONS, "{", "}", "AND"))
    transform ((JETONS, "{", "}", "OR"))
    turn ((JETONS, «SYN (",", GR_THESAURUS) ', 'AND'))
    turn ((JETONS, «SYN (",", GR_THESAURUS) ', 'GOLD'))
    transform ((JETONS, «?)) {","} "," AND"))/seq >
    transform ((JETONS, «?)) {","} "," GOLD"))/seq >



    (1) > 0

  • Please help: JavaScript Exception: error calling the selection function: Microsoft Edge, Windows 10

    Hello...

    Can someone help me with this? It happens on a site that just went live, so the customer is very anxious. All is well in Chrome and Safari...

    www.realfoodfakefood.com

    I contacted Adobe... the problem was caused because a link on the home page was not working. Microsoft Edge didn't like that much. Link fixed, issue went, I'm happy! This can be closed.

  • Please help, e by soving the query

    SQL > SELECT * FROM THE Department;

    DEPTNO DNAME LOC

    --------------------------------------------------------------------------------
    --------------
    --------------------------------------------------------------------------------
    50 SALES NEW DELHI
    10 ACCOUNTS NEW YORK
    SEARCH 20 DALLAS
    30 SALES CHICAGO
    40 OPERATIONS BOSTON

    I WANT THE OUTPUT AS->


    Column name


    --------------------------------------------------------------------------------
    ACCOUNTING
    10
    NEW YORK CITY
    20
    SEARCH
    DALLAS
    CHICAGO
    SALES
    30
    BOSTON
    OPERATIONS
    40
    SALES
    50
    NEW DELHI

    Like this..

    SQL> with dep
      2  as
      3  (
      4     select row_number() over(order by deptno) rno, d.*
      5       from dept d
      6  )
      7  select 1 no, rno, to_char(deptno) colname from dep
      8  union all
      9  select 2 no, rno, dname from dep
     10  union all
     11  select 3 no, rno, loc from dep
     12  order by rno, no
     13  /
    
            NO        RNO COLNAME
    ---------- ---------- ----------------------------------------
             1          1 10
             2          1 ACCOUNTING
             3          1 NEW YORK
             1          2 20
             2          2 RESEARCH
             3          2 DALLAS
             1          3 30
             2          3 SALES
             3          3 CHICAGO
             1          4 40
             2          4 OPERATIONS
    
            NO        RNO COLNAME
    ---------- ---------- ----------------------------------------
             3          4 BOSTON
    
    12 rows selected.
    

Maybe you are looking for

  • Good IP address of my router extreme need.

    I watched the network TCP/IP section, however its is a short number in the router and not the number long normal 192. etc. which is necessary to be able to access the URL configuration thiungs.  Does anyone know how to find the real IP address?

  • HP Pavilion 17 17-f114dx: HP not Pavilion no office

    Hello I have my new HP Pavilion 17 17-f114dx for only a month and it worked great until today.  When I start it, it now takes slightly longer to start and log in.  When I connect, I see my office, but instead, I get a blank screen.  I am able to see

  • Keyboard shortcut to copy to the Clipboard in REPORT

    Hello I have not found in the help pages, but there may be a shortcut key for the file-> Clipboard hidden anywhere? If not, is there a possibility to customize keyboard shortcuts? Thank you PHEX

  • help for XAV - 60

    Hello, your help to see if they have any master code to unlock my car radio model XAV-60, this step

  • Keyboard problems after upgrade to Windows 8 Pro

    Model 610-1280qd After the update, I found that my wireless HP came with the computer, keyboard no longer allows me to use the number keys and special characters above the letters. Device Manager displays 5 entries on the keyboard, including a PS2 Ke