The join SQL query help

I'm just having a bit of troubel get a correct join query - I thought it was an Inner Join, but I don't get the results I expect.

My table structure is:

Table: lodges

LodgeID (PK)

Lodge

etc.

Table: implemented application

NominationID (PK)

Category

LodgeID

Year

So I try to use this structure to replicate this page:

http://www.safariawards.com/nominees12/

That is to say a list of boxes for each category, they are appointed on.

The query I've tried looks like this:

SELECT appointments. LodgeID, lodges. Lodge, applications. NominationID, applications. Lodges INNER JOIN applications category IT lodges. LodgeID = nominated. NominationID WHERE category = "Best property of Safari in southern Africa" ORDER BY Lodge

But this product:

http://www.safariawards.com/nominees12/southernafrica.php

Its the right number of results, but not the list on the right of the boxes - for example British Airwways is not LodgeID 786

If anyone could help with the SQL right for what would be well appreciated.

That you join on the wrong column. Try this:

SELECT appointments. LodgeID, lodges. Lodge, applications. NominationID, applications. Lodges INNER JOIN applications category IT lodges. LodgeID = nominated. LodgeID WHERE category = "Best property of Safari in southern Africa" ORDER BY Lodge

Tags: Dreamweaver

Similar Questions

  • Join SQL query help

    I have two DEVICE and CONTACT tables. The tables are joined for CONTACT_ID DEVICE_ID. I want to print device_ID and the corresponding coordinates on the lower contact. PRIORITY.
    SQL> describe DEVICE;
    DEVICE_ID              NOT NULL VARCHAR2(50)
    
    SQL> describe CONTACT;
    CONTACT_ID               NOT NULL VARCHAR2(50)
    CONTACT_TYPE             NOT NULL VARCHAR2(4)
    PRIORITY                 NOT NULL DOUBLE PRECISION
    LASTNAME                 NOT NULL VARCHAR2(30)
    FIRSTNAME                NOT NULL VARCHAR2(80)
    
    SQL> SELECT a.DEVICE_ID, b.LASTNAME,b.PRIORITY from DEVICE a, CONTACT b where a.DEVICE_ID = 'DEVICEA' and a.DEVICE_ID=b.CONTACT_ID(+);
    DEVICE_ID              LASTNAME    FIRSTNAME PRIORITY CONTACT_TYPE
    ---------------------- ----------- --------- -------- ------------
    DEVICEA                CONTACT1     GN               1 ROUT
    DEVICEA                CONTACT2     Hans             2 ROUT
    How to print a single record with the CONTACT the lowest. PRIORITY?

    Thank you
    Ravi

    rmalghan wrote:
    Thank you Frank, Sundar and Sean. I had less than 3 to work. Two questions. My table of DEVICES has 31936 records.
    1. the first one returned 30207, 31936 records 2nd and 3rd a 30348. Since the 2nd result resembles what I expected, the 1st and 3rd one seem to miss some records. For troubleshooting, I tried to limit the query to a few devices, but do not understand why the difference. Any suggestions?

    The 2nd query not check for type_contact = 'ROUT', it is not surprising that it returns more rows.
    The request of 3rd fact actually an inner join. The "WHERE c.rnum = 1" condition is applied after the join, so he rejects all rows that have been added due to the outer join (which is where all the columns of c are NULL). You probably meant to say:

    LEFT OUTER JOIN got_rnum c ON  d.DEVICE_ID     = c.CONTACT_ID
                               AND c.rnum          = 1; 
    

    without a WHERE clause.

    2. are there advantages in terms of efficiency. 2nd one does not seem to run faster, so I think it's the best. Any comments?

    SELECT a.DEVICE_ID, b.LASTNAME,b.FIRSTNAME,b.PRIORITY
    FROM DEVICE a, CONTACT b
    where
    a.DEVICE_ID=b.CONTACT_ID(+) and
    b.CONTACT_TYPE = 'ROUT' and
    b.PRIORITY = (select min(b1.PRIORITY ) from CONTACT b1 where b1.CONTACT_ID = b.CONTACT_ID);
    
    30207 rows selected (10.12 seconds)
    
    SELECT DEVICE_ID, LASTNAME, PRIORITY
    FROM (
    SELECT a.DEVICE_ID, b.LASTNAME, b.PRIORITY, ROW_NUMBER() OVER (PARTITION BY a.DEVICE_ID ORDER BY b.PRIORITY) row_num
    from DEVICE a, CONTACT b
    where a.DEVICE_ID=b.CONTACT_ID(+))
    WHERE row_num = 1;
    
    31936 rows selected (6.68 seconds)
    
    WITH got_rnum AS (
    SELECT LASTNAME, FIRSTNAME, PRIORITY, CONTACT_TYPE, CONTACT_ID,
    ROW_NUMBER () OVER ( PARTITION BY  CONTACT_ID ORDER BY priority) AS rnum
    FROM contact
    where CONTACT_TYPE = 'ROUT'
    )
    
    SELECT d.DEVICE_ID, c.LASTNAME, c.FIRSTNAME, c.PRIORITY
    FROM device d
    JOIN got_rnum c ON d.DEVICE_ID     = c.CONTACT_ID(+)
    WHERE c.rnum = 1; 
    
    30348 rows selected (9.07 seconds)
    

    This calendar is not very accurate. One that you run first is likely to be slower, because the data are less likely to be stored in the memory cache.

    The 2nd query has only 3 columns in the result set. Which probably doesn't change the speed a lot, but you should fix it anyway.

  • SQL query - help with join

    Dear friends,

    Version of DB - 11.1.0.7... , I'm stuck with SQL basics today... need your help...

    The slot SQL tells me "cache them locks library" in the database that I will put up as a proactive measure.

    I'll be it works via shell script and include the table gv instance_name $ instance ... I'm a little confused as to how a 3rd table "gv$ instance ' can be introduced into the query in order to make the instance_name in the result set...

    SELECT * FROM)

    SELECT / * + LEADING (a) USE_HASH (u) * /.

    instance_name, INST_ID select, blocking_inst_id, blocking_session, username, session_id, sql_id, current_obj #,.

    DECODE (sql_opcode, 1, 'CREATE TABLE', 2, 'INSERT') as "order."

    Event, mod(P1,16) p1, p2, p3

    COUNT (*) totalseconds

    , SUM (CASE WHEN wait_class = 'Application' THEN 1 ELSE 0 END) 'Application '.

    Of

    (SELECT

    a.*

    , TO_CHAR (CASE WHEN session_state = 'WAITING' THEN ELSE null END p1, '0XXXXXXXXXXXXXXX') p1hex

    , TO_CHAR (CASE WHEN session_state = "PENDING" THEN p2 ELSE null END, '0XXXXXXXXXXXXXXX') p2hex

    , TO_CHAR (CASE WHEN session_state = "PENDING" THEN ELSE null END p3, '0XXXXXXXXXXXXXXX') p3hex

    SGS $ active_session_history one) a

    u dba_users

    WHERE

    a.user_id = u.user_id

    AND sample_time BETWEEN sysdate-90 /(24*60) AND sysdate

    - AND a test of ('library cache lock', 'library cache pin")

    AND event like '% library '.

    GROUP BY

    INST_ID select, blocking_inst_id, blocking_session, username, session_id, sql_id, current_obj #,.

    DECODE (sql_opcode, 1, 'CREATE TABLE', 'INSERT', 2),

    event, mod (p1, 16), p2, p3

    Having count (*) > 5

    ORDER BY

    TotalSeconds DESC

    , INST_ID select, blocking_session, username, session_id, sql_id, current_obj #, 'Order', event

    )

    WHERE

    ROWNUM < = 20

    /

    replace

    instance_name

    by

    (select instance_name gv$ instance where INST_ID select = a.inst_id) instance_name

    or select... in... a, u, gv$ instance where... and gv$ instance.inst_id (+) = a.inst_id...

  • performance issue with the Oracle SQL query

    Dears

    Good evening

    I am new to begin to use Oracle SQL, I have a sql query which takes longer to run in production.

    Each table in the query contains 1.2 million records and DBA suggested using the "Oracle - tips. I don't have good knowledge on this subject and the difficulties to implement this advice for imrpovise performance. In the product the jobs Informatica are failed and stuck with this problem of query performance.

    I ask this forum for an emergency for me to solve this problem by using "advice". kindly help me.

     

    SELECT
    CASE.ID,
    CASE. DTYPE,
    CASE. Version
    CASE. EXTERNAL_REF,
    CASE. CREATION_TS,
    RQ. TYPE
    Of
    PAS_CASE CASE,
    AS_REQUEST RQ,
    CN PAS_CONTEXT
    where rq.case_id = case.id
    AND rq.id = cn.request_id
    and rq. DTYPE = "MAINREQUEST."
    and rq. TYPE in
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )
    and CN. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
    AND CAST (CN. CREATION_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
    AND
    CAST (CN. CREATION_TS AS DATE) < TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    -2nd request

    SELECT
    RA.ID,
    RHEUMATOID ARTHRITIS. Version
    RHEUMATOID ARTHRITIS. REQUEST_ID,
    RA.NAME,
    RHEUMATOID ARTHRITIS. VALUE,
    RHEUMATOID ARTHRITIS. LOB_ID,
    RHEUMATOID ARTHRITIS. DTYPE,
    RHEUMATOID ARTHRITIS. CREATION_TS,
    TASK. MAIN_REQ_TYPE
    PAS_REQUESTATTRIBUTE RA
    Join
    (
    Select tsk.ID, tsk. TYPE, main_req_type main_req.
    of tsk PAS_REQUEST
    Join
    (
    Select cn.id as context_id, rq. TYPE main_req_type
    of PAS_REQUEST rq
    Cn PAS_CONTEXT
    where rq.id = cn.request_id
    and rq. DTYPE = "MAINREQUEST."
    and rq. TYPE in
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
    )
    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
    and cn.ID between the 20141999999999999 AND 20141800000000000
    and rq.ID between the 20141999999999999 AND 20141800000000000

    ) main_req
    On tsk.parent_context_id = main_req.context_id
    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
    and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1
    ) task
    on the RA REQUEST_ID = task.ID
    and RA.ID between $$ LOW_ID1 AND $$ HIGH_ID1
    UNION

    SELECT
    RA.ID,
    RHEUMATOID ARTHRITIS. Version
    RHEUMATOID ARTHRITIS. REQUEST_ID,
    RA.NAME,
    RHEUMATOID ARTHRITIS. VALUE,
    RHEUMATOID ARTHRITIS. LOB_ID,
    RHEUMATOID ARTHRITIS. DTYPE,
    RHEUMATOID ARTHRITIS. CREATION_TS,
    MAIN_REQ. TYPE
    PAS_REQUESTATTRIBUTE RA
    Join
    (
    Select rq.id, rq.type
    of PAS_REQUEST rq
    Cn PAS_CONTEXT
    where rq.id = cn.request_id
    and rq. DTYPE = "MAINREQUEST."
    and rq. TYPE in
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
    )
    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
    and cn.ID between the 20141999999999999 AND 20141800000000000
    and rq.ID between the 20141999999999999 AND 20141800000000000
    ) main_req
    on the RA REQUEST_ID = main_req.ID

    -3rd request

    SELECT

    RB.ID,

    RB. DTYPE,

    RB. Version

    RB. TYPE,

    RB. CREATION_TS,

    RB. TASK_ID,

    RB. Color

    RB. GLOBAL_RESULT,

    TASK. MAIN_REQ_TYPE

    Of

    PAS_RESULTBLOCK RB

    Join

    (

    Select tsk.ID, tsk. TYPE, main_req_type main_req.

    of tsk PAS_REQUEST

    Join

    (

    Select cn.id as context_id, rq. TYPE main_req_type

    of PAS_REQUEST rq

    Cn PAS_CONTEXT

    where rq.id = cn.request_id

    and rq. DTYPE = "MAINREQUEST."

    and rq. TYPE in

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)

    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    and cn.ID between the 20141999999999999 AND 20141800000000000

    and rq.ID between the 20141999999999999 AND 20141800000000000

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    ) task

    We rb.task_id = task.ID

    and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    and RB. TYPE is not null

    and RB. TYPE IN

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    UNION

    SELECT

    RB.ID,

    RB. DTYPE,

    RB. Version

    RB. TYPE,

    RB. CREATION_TS,

    RB. TASK_ID,

    RB. Color

    RB. GLOBAL_RESULT,

    TASK. MAIN_REQ_TYPE

    Of

    PAS_RESULTBLOCK RB

    Join

    (

    Select tsk.ID, tsk. TYPE, main_req_type main_req.

    of tsk PAS_REQUEST

    Join

    (

    Select cn.id as context_id, rq. TYPE main_req_type

    of PAS_REQUEST rq

    Cn PAS_CONTEXT

    where rq.id = cn.request_id

    and rq. DTYPE = "MAINREQUEST."

    and rq. TYPE in

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)

    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    and cn.ID between the 20141999999999999 AND 20141800000000000

    and rq.ID between the 20141999999999999 AND 20141800000000000

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    ) task

    We rb.task_id = task.ID

    and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    and RB. TYPE is nullSELECT

    RB.ID,

    RB. DTYPE,

    RB. Version

    RB. TYPE,

    RB. CREATION_TS,

    RB. TASK_ID,

    RB. Color

    RB. GLOBAL_RESULT,

    TASK. MAIN_REQ_TYPE

    Of

    PAS_RESULTBLOCK RB

    Join

    (

    Select tsk.ID, tsk. TYPE, main_req_type main_req.

    of tsk PAS_REQUEST

    Join

    (

    Select cn.id as context_id, rq. TYPE main_req_type

    of PAS_REQUEST rq

    Cn PAS_CONTEXT

    where rq.id = cn.request_id

    and rq. DTYPE = "MAINREQUEST."

    and rq. TYPE in

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)

    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    and cn.ID between the 20141999999999999 AND 20141800000000000

    and rq.ID between the 20141999999999999 AND 20141800000000000

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    ) task

    We rb.task_id = task.ID

    and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    and RB. TYPE is not null

    and RB. TYPE IN

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    UNION

    SELECT

    RB.ID,

    RB. DTYPE,

    RB. Version

    RB. TYPE,

    RB. CREATION_TS,

    RB. TASK_ID,

    RB. Color

    RB. GLOBAL_RESULT,

    TASK. MAIN_REQ_TYPE

    Of

    PAS_RESULTBLOCK RB

    Join

    (

    Select tsk.ID, tsk. TYPE, main_req_type main_req.

    of tsk PAS_REQUEST

    Join

    (

    Select cn.id as context_id, rq. TYPE main_req_type

    of PAS_REQUEST rq

    Cn PAS_CONTEXT

    where rq.id = cn.request_id

    and rq. DTYPE = "MAINREQUEST."

    and rq. TYPE in

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)

    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    and cn.ID between the 20141999999999999 AND 20141800000000000

    and rq.ID between the 20141999999999999 AND 20141800000000000

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    ) task

    We rb.task_id = task.ID

    and rb.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    and RB. TYPE is null

    -4th query

    SELECT
    RI.ID,
    UII DTYPE,
    UII Version
    UII RESULTBLOCK_ID,
    RI.NAME,
    UII VALUE,
    UII UNIT,
    UII Color
    UII LOB_ID,
    UII CREATION_TS,
    UII SEQUENCE,
    UII DETAILLEVEL,
    RES_BLK. MAIN_REQ_TYPE
    Of
    RI PAS_RESULTITEM
    Join
    (
    Select
    rb.ID, rb. TYPE rb_type, task. TYPE as the task_type, task. pas_resultblock rb main_req_type
    Join
    (
    Select tsk.ID, tsk. TYPE, main_req_type main_req.
    of tsk PAS_REQUEST
    Join
    (
    Select cn.id as context_id, rq. TYPE main_req_type
    of PAS_REQUEST rq
    Cn PAS_CONTEXT
    where rq.id = cn.request_id
    and rq. DTYPE = "MAINREQUEST."
    and rq. TYPE in
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
    )
    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
    and cn.ID between the 20141999999999999 AND 20141800000000000
    and rq.ID between the 20141999999999999 AND 20141800000000000
    ) main_req
    On tsk.parent_context_id = main_req.context_id
    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
    and tsk.ID between the 20141999999999999 AND 20141800000000000
    ) task
    We rb.task_id = task.ID
    and rb.ID between the 20141999999999999 AND 20141800000000000
    and RB. TYPE IN
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
    )
    ) res_blk
    On ri.resultblock_id = res_blk.ID
    where IN RI.NAME
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
    )
    and RI.ID between the 20141999999999999 AND 20141800000000000
    and RI.NAME is not null
    UNION

    Select
    RI.ID,
    UII DTYPE,
    UII Version
    UII RESULTBLOCK_ID,
    RI.NAME,
    UII VALUE,
    UII UNIT,
    UII Color
    UII LOB_ID,
    UII CREATION_TS,
    UII SEQUENCE,
    UII DETAILLEVEL,
    RES_BLK. MAIN_REQ_TYPE
    of pas_resultitem ri
    Join
    (
    Select
    rb.ID, rb. TYPE rb_type, task. TYPE as the task_type, task. pas_resultblock rb main_req_type
    Join
    (
    Select tsk.ID, tsk. TYPE, main_req_type main_req.
    of tsk PAS_REQUEST
    Join
    (
    Select cn.id as context_id, rq. TYPE main_req_type
    of PAS_REQUEST rq
    Cn PAS_CONTEXT
    where rq.id = cn.request_id
    and rq. DTYPE = "MAINREQUEST."
    and rq. TYPE in
    (
    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.
    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.
    )
    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')
    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)
    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)
    and cn.ID between the 20141999999999999 AND 20141800000000000
    and rq.ID between the 20141999999999999 AND 20141800000000000
    ) main_req
    On tsk.parent_context_id = main_req.context_id
    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')
    and tsk.ID between the 20141999999999999 AND 20141800000000000
    ) task
    We rb.task_id = task.ID
    and rb.ID between the 20141999999999999 AND 20141800000000000
    ) res_blk
    On ri.resultblock_id = res_blk.ID
    where RI.ID between 20141800000000000 20141999999999999 AND
    and RI.NAME is null

    -REQUEST OF 5HT

    SELECT

    TSK.ID,

    TSK. Version

    TSK. DTYPE,

    TSK. CASE_ID,

    TSK. TYPE,

    TSK. CORRELATION_ID,

    TSK. INITIATOR,

    TSK. EXECUTOR,

    TSK. CATEGORY,

    TSK. PARENT_CONTEXT_ID,

    TSK. CREATION_TS,

    MAIN_REQ. MAIN_REQ_TYPE

    Of

    TSK PAS_REQUEST

    Join

    (

    Select cn.id as context_id, rq. TYPE main_req_type

    of PAS_REQUEST rq

    Cn PAS_CONTEXT

    where rq.id = cn.request_id

    and rq. DTYPE = "MAINREQUEST."

    and rq. TYPE in

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)

    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    and cn.ID between the 20141999999999999 AND 20141800000000000

    and rq.ID between the 20141999999999999 AND 20141800000000000

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk. DTYPE in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.ID between $$ LOW_ID1 AND $$ HIGH_ID1

    UNION

    Select

    MREQ.ID,

    MREQ. Version

    MREQ. DTYPE,

    MREQ. CASE_ID,

    MREQ. TYPE,

    MREQ. CORRELATION_ID,

    MREQ. INITIATOR,

    MREQ. EXECUTOR,

    MREQ. CATEGORY,

    MREQ. PARENT_CONTEXT_ID,

    MREQ. CREATION_TS,

    MREQ. TYPE

    of PAS_REQUEST mreq

    Cn PAS_CONTEXT

    where mreq.id = cn.request_id

    and mreq. DTYPE = "MAINREQUEST."

    and mreq. TYPE in

    (

    'bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ',' bgc.tbf.repair.vap', ' bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ',' bgc.cbm ',' bgc.dar.e2etest.preparation', ' bgc.chc.polling '.

    )

    and cn. STATUS ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and CAST (cn. END_TS AS DATE) > = TO_DATE ('2014-05-06 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS)

    and CAST (cn. END_TS AS DATE) < = TO_DATE ('2014-05-06 23:59:59 ',' ' YYYY-MM-DD HH24:MI:SS)

    and cn.ID between the 20141999999999999 AND 20141800000000000

    and mreq.ID between the 20141999999999999 AND 20141800000000000

    Tips will be may not be necessary (proportional to the cardinalities need)


    Select pc.id, pc.dtype, pc.version, pc.external_ref, pc.creation_ts, rq.type

    from pas_case

    as_request rq,

    CN pas_context

    where rq.case_id = pc.id

    and rq.id = cn.request_id

    and rq.dtype = 'MAINREQUEST. '

    and rq.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',

    'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and cn.creation_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    and cn.creation_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">

    -2nd request

    with

    main_request as

    (select / * + materialize * /)

    CN.ID as context_id, rq.type as main_req_type

    of pas_request rq

    Join

    CN pas_context

    On rq.id = cn.request_id

    and rq.dtype = 'MAINREQUEST. '

    and rq.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.chc.polling',

    'bgc.tbf.repair.vap ',' bgc.dar.e2etest', ' bgc.dar.e2etest.intermediate.execution ',.

    'bgc.cbm ','bgc.dar.e2etest.preparation '.

    )

    and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">

    and cn.id between 20141800000000000 and 20141999999999999

    and rq.id between 20141800000000000 and 20141999999999999

    )

    Select ra.id, ra.version, ra.request_id, ra.name, ra.value, ra.lob_id, ra.dtype, ra.creation_ts, task.main_req_type

    of pas_requestattribute ra

    Join

    (select tsk.id, tsk.type, main_req.main_req_type

    from pas_request tsk

    Join

    main_request main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.id between $$ low_id1 and $$ high_id1

    ) task

    We ra.request_id = task.id

    and ra.id between $$ low_id1 and $$ high_id1

    Union

    Select ra.id, ra.version, ra.request_id, ra.name, ra.value, ra.lob_id, ra.dtype, ra.creation_ts, main_req.type

    of pas_requestattribute ra

    Join

    main_request main_req

    On ra.request_id = main_req.context_id

    -3rd request

    Select rb.id, rb.dtype, rb.version, rb.type, rb.creation_ts, rb.task_id, rb.color, rb.global_result, task.main_req_type

    of pas_resultblock rb

    Join

    (select tsk.id, tsk.type, main_req.main_req_type

    from pas_request tsk

    Join

    (select cn.id as context_id, rq.type as main_req_type

    of pas_request rq

    Join

    CN pas_context

    On rq.id = cn.request_id

    and rq.dtype = 'MAINREQUEST. '

    and rq.type in ('bgc.dar.vap.resolution.advice ','bgc.dar.e2etest.execution ',

    'bgc.tbf.repair.vap ','bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ','bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">

    and cn.id between 20141800000000000 and 20141999999999999

    and rq.id between 20141800000000000 and 20141999999999999

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.id between $$ low_id1 and $$ high_id1

    ) task

    We rb.task_id = task.id

    and rb.id between $$ low_id1 and $$ high_id1

    where the type is null

    or (type is not null

    type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution ', ' bgc.tbf.repair.vap',

    'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    )

    -4th query

    Select ri.id, ri.dtype, ri.version, ri.resultblock_id, ri.name, ri.value, ri.unit, ri.color, ri.lob_id.

    RI.creation_ts, RI. Sequence, RI. DetailLevel, res_blk.main_req_type

    of pas_resultitem ri

    Join

    (select rb.id, rb.type as rb_type, task.type as task_type, task.main_req_type)

    of pas_resultblock rb

    Join

    (select main_req_type, tsk.id, tsk.type, main_req.)

    from pas_request tsk

    Join

    (select cn.id as context_id, rq.type as main_req_type

    of pas_request rq

    Join

    CN pas_context

    On rq.id = cn.request_id

    and rq.dtype = 'MAINREQUEST. '

    and rq.type in ('bgc.dar.vap.resolution.advice ','bgc.dar.e2etest.execution ',

    'bgc.tbf.repair.vap ','bgc.dar.e2etest ',.

    'bgc.dar.e2etest.intermediate.execution ','bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">

    and cn.id between 20141800000000000 and 20141999999999999

    and rq.id between 20141800000000000 and 20141999999999999

    ) main_req

    On tsk.parent_context_id = main_req.context_id

    and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.id between 20141800000000000 and 20141999999999999

    ) task

    We rb.task_id = task.id

    and rb.id between 20141800000000000 and 20141999999999999

    and rb.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',

    'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    ) res_blk

    On ri.resultblock_id = res_blk.id

    and ri.id between 20141800000000000 and 20141999999999999

    where ri.name is null

    or (ri.name is not null

    and ri.name in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',

    'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    )

    -5th application

    with

    main_request as

    (select / * + materialize * / )

    mreq.ID, mreq.version, mreq.dtype, mreq.case_id, mreq.type, mreq.correlation_id, mreq. Initiator, mreq. Executor,

    mreq. Category, mreq.parent_context_id, mreq.creation_ts, mreq.type

    of pas_request mreq

    Join

    CN pas_context

    On mreq.id = cn.request_id

    and mreq.dtype = 'MAINREQUEST. '

    and mreq.type in ('bgc.dar.vap.resolution.advice ',' bgc.dar.e2etest.execution', ' bgc.tbf.repair.vap',

    'bgc.dar.e2etest ',' bgc.dar.e2etest.intermediate.execution', ' bgc.cbm ',.

    'bgc.dar.e2etest.preparation ','bgc.chc.polling '.

    )

    and cn.status in ('FINISHED', 'CANCEL', 'TIMEOUT', 'ERROR')

    and cn.end_ts > = to_timestamp ('2014-05-06 00:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    and cn.end_ts<= to_timestamp('2014-05-06="" 23:59:59.999999','yyyy-mm-dd="">

    and cn.id between 20141800000000000 and 20141999999999999

    and mreq.id between 20141800000000000 and 20141999999999999

    )

    Select tsk.id, tsk.version, tsk.dtype, tsk.case_id, tsk.type, tsk.correlation_id, tsk.initiator, tsk.executor,

    TSK. Category, tsk.parent_context_id, tsk.creation_ts, main_req.main_req_type

    from pas_request tsk

    Join

    main_request main_req

    On tsk.parent_context_id = main_req.id

    and tsk.dtype in ('ANALYSIS_TASK', 'DECISION_TASK')

    and tsk.id between $$ low_id1 and $$ high_id1

    Union

    SELECT id, version, dtype, case_id, type, correlation_id, initiator, executor,

    category, type parent_context_id, creation_ts

    of main_request

    Concerning

    Etbin

  • SQL query help (we connect by clause level)

    Hi all
    I have this application developed with data with the clause.
     With dat As
    (
      select '@AAA @SSS @DDD' col1 from dual union all
      select '@ZZZ @XXX @TTT @RRR @ZZA' col1 from dual 
    )
    Select regexp_substr( col1 , '[^@][A-Z]+',1,level) Show from dat
    connect by level  <= regexp_count(col1, '@');
    Output current: -.
    SHOW
    -----------------------
    AAA
    SSS
    DDD
    RRR
    ZZA
    TTT
    RRR
    ZZA
    XXX
    DDD
    RRR
    
    SHOW
    -----------------------
    ZZA
    TTT
    RRR
    ZZA
    . . .
    . . .
    1st row comes very well, but the next line data copy. And the number of total records = 30. I tried with some, but not worked.
    Expected results: -.
    SHOW
    -----------------------
    AAA
    SSS
    DDD
    ZZZ 
    XXX 
    TTT 
    RRR 
    ZZA
    I need some changes on my request and I am not able to see that. So anyone can add to that or can also provide a different solution also.

    Thank you!
    Ashutosh

    Thanks for providing the loan to the use of query. :)

    Here's a solution :-(tested on 10 g, do not have 11 g at hand)

    For 11g, just use regexp_count instead of functions of the length.

    With dat As
    (
      select '@AAA @SSS @DDD' col from dual union all
      select '@ZZZ @XXX @TTT @RRR @ZZA' col1 from dual
    )
    Select regexp_substr( col, '[^@][A-Z]+',1,level) Show from dat
    connect by nocycle level  <= length(col) - length(translate(col, 'A@', 'A'))
           and col = prior col
           and prior sys_guid() is not null;
    
    SHOW
    ------------------------
    AAA
    SSS
    DDD
    ZZZ
    XXX
    TTT
    RRR
    ZZA                      
    
     8 rows selected
    
  • SQL query help needed in the Clause type

    Hello

    I'm currently learning Clause type. How can I write in the clause type to get the result below:

    I have a table like this

    DEPTNO ENAME

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

    20 SMITH

    CELINE 10

    BOND 20

    ALLEN 30

    WARD 30

    20 JONES

    30 MARTIN

    30 BLAKE

    10 CLARK

    SCOTT 20

    10 KING

    30 TURNER

    20 ADAMS

    30 JAMES

    20 FORD

    10 MILLER

    I want the output should look like this

    DEPTNO ENAME

    ------     -----

    CELINE 10, CLARK, KING, MILLER

    20 JONES, ADAMS, BOND, FORD, SCOTT, SMITH

    30 MARTIN, JAMES BLAKE, WARD, TURNER, ALLEN

    Hear is the script I am currently working on.

    with emp_group as

    (

    Select 20 deptno, ename 'SMITH' Union double all the

    choose 10, 'CÉLINE' from dual union all

    Select 20, "BOND" of all the double union

    Select 30, 'ALLEN' from dual union all

    Select 30, 'WARD' of all the double union

    Select 20, "JONES' from dual union all

    Select 30, 'MARTIN' from dual union all

    Select 30, "BLAKE" from dual union all

    choose 10, 'CLARK' from dual union all

    Select 20, 'SCOTT' from dual union all

    choose 10, 'KING' of the dual union all

    Select 30, 'TURNER' from dual union all

    Select 20, 'ADAMS' from dual union all

    Select 30, 'JAMES' of the dual union all

    Select 20, 'FORD' Union double all the

    choose 10, 'MILLER' from dual

    )

    Select

    DEPTNO

    A1

    of emp_group

    model

    ignore the nav

    partition (deptno)

    dimension (ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename DESC) rn)

    measures (ename, LPAD(' ', 100) A1)

    rules)

    A1 [rn > 0] = ename [cv ()],

    A1 [0] = ename [cv ()]

    )

    order by deptno

    ;

    your help is very appreciated.

    Thank you in advance.

    Try this.

    Select

    *

    Of

    (

    with emp_group as

    (

    Select 20 deptno, ename 'SMITH' Union double all the

    choose 10, 'CÉLINE' from dual union all

    Select 20, "BOND" of all the double union

    Select 30, 'ALLEN' from dual union all

    Select 30, 'WARD' of all the double union

    Select 20, "JONES' from dual union all

    Select 30, 'MARTIN' from dual union all

    Select 30, "BLAKE" from dual union all

    choose 10, 'CLARK' from dual union all

    Select 20, 'SCOTT' from dual union all

    choose 10, 'KING' of the dual union all

    Select 30, 'TURNER' from dual union all

    Select 20, 'ADAMS' from dual union all

    Select 30, 'JAMES' of the dual union all

    Select 20, 'FORD' Union double all the

    choose 10, 'MILLER' from dual

    )

    Select

    DEPTNO

    names

    rn

    of emp_group

    model

    ignore the nav

    partition (deptno)

    dimension of)

    ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename) rn

    )

    measures (ename, cast (null as names of varchar2 (40)))

    rules

    (

    names [any] order by desc = ename [cv ()] rn | «, » || names [cv () + 1]

    )

    order by deptno

    )

    where rn = 1

    Best regards, Andrei

  • The SQL query help

    with t as

    (

    Select to_date (January 1, 2014 "," dd-mon-yyyy ') col1, 'a' col2, col3 1.04 by union double all the

    Select to_date (5 January 2014 ',' mon-dd-yyyy "") col1, 'a' col2, col3 1.02 Union double all the

    Select to_date (8 January 2014 ',' mon-dd-yyyy "") col1, col2, col3 1.01 Union ' b' double all the

    Select to_date (January 10, 2014 "," dd-mon-yyyy "") col1, col2, col3 1.05 Union ' b' double all the

    Select to_date (January 10, 2014 "," dd-mon-yyyy "") col1, col2, col3 2.00 Union ' b' double all the

    Select to_date (January 10, 2014 "," dd-mon-yyyy "") col1, col2 'c', col3 3.05 Union double all the

    Select to_date (January 14, 2014 "," dd-mon-yyyy "") col1, col2, col3 6.00 Union ' b' double all the

    Select to_date (15 January 2014 "," dd-mon-yyyy "") col1, col2, col3 6.10 Union ' b' double all the

    Select to_date (15 January 2014 "," dd-mon-yyyy ') col1, col2, col3 6.05 of the double ' c'

    )

    Select t.*

    t;

    OUTPUT:

    COL1 COL2 COL3

    01/01/2014 by 1.04

    05/01/2014 a 1.02

    08/01/2014 b 1.01

    10/01/2014 b 1.05

    10/01/2014 b 2

    10/01/2014 c 3.05

    14/01/2014 b 6

    15/01/2014 b 6.1

    15/01/2014 c 6.5

    Required power must be:

    COL1 COL2 COL3

    01/01/2014 by 1.04

    05/01/2014 a 1.02

    08/01/2014 b 1.01

    10/01/2014 b 1.01

    10/01/2014 b 1.01

    10/01/2014 c 1.01

    14/01/2014 b 6

    15/01/2014 b 6

    15/01/2014 c 6

    If we found the dates duplicate, we need update COL3 value with the previous value of max (date) value COL3.

    Please save my life!

    Hello

    Try this:

    WITH
    t AS
    (SELECT to_date (January 1, 2014 "," dd-mon-yyyy ') col1, 'a' col2, 1.04 col3 FROM dual)
    UNION ALL
    SELECT to_date (5 January 2014 ',' mon-dd-yyyy "") col1, 'a' col2, 1.02 col3 FROM dual
    UNION ALL
    SELECT to_date (8 January 2014 ',' mon-dd-yyyy "") col1, col2 'b', 1.01 col3 FROM dual
    UNION ALL
    SELECT to_date (January 10, 2014 ',' mon-dd-yyyy "") col1, col2 'b', 1.05 col3 FROM dual
    UNION ALL
    SELECT to_date (January 10, 2014 ',' mon-dd-yyyy "") col1, col2 'b', 2,00 col3 FROM dual
    UNION ALL
    SELECT to_date (January 10, 2014 ',' mon-dd-yyyy "") col1, col2 'c', 3.05 col3 FROM dual
    UNION ALL
    SELECT to_date (January 14, 2014 ',' mon-dd-yyyy "") col1, col2 'b', 6.00 col3 FROM dual
    UNION ALL
    SELECT to_date (15 January 2014 ',' mon-dd-yyyy "") col1, col2 'b', 6,10 col3 FROM dual
    UNION ALL
    SELECT to_date (15 January 2014 ',' mon-dd-yyyy "") col1, col2 'c', 6.05 col3 FROM dual
    )
    a, as
    (
    SELECT
    col1
    col2
    col3
    count (col1) on count_col1 (col1 partition)

    Of
    t
    )

    Select
    a.Col1
    a.col2
    a.col3
    case when a.count_col1 = 1
    then a.col3
    Max (t.col3) else keep (dense_rank of the first order by t.col1 desc)


    end                                                                         new_col3

    Of
    one
    left join (t.col1 t<>

    Group
    a.Col1
    a.col2
    a.col3
    a.count_col1
     
    order by
    a.Col1

    ;

    COL1 COL2 COL3 NEW_COL3
    --------- ---- ---- --------
    1 January 14 a 1.04 1.04
    5 January 14 a 1.02 1.02
    January 8, 14 b 1.01 1.01
    January 10, 14 b 1.05 1.01
    January 10, 14 2 b 1.01
    10 January 14 c 3.05 1.01
    January 14, 14 b 6 of 6
    15 January 14 b 6.1 6
    15 January 14 c 6.05 6

    9 selected lines

    Kind regards

    Peter

  • Conversion of SQL Query Help

    Hello, I'm doing a migration of SQL Server T - SQL to oracle 11 g PL/SQL, and I don't want to use a global temporary table; Instead, consider using sliders and pl/sql table.

    I got hit in a scenario where I need to convert the following in a single sql statement.

    Stage of T - SQL:
    ============

    Insert (#ActCde)
    InvntrySbLdgrChngeID
    DlHdrID
    DlDtlID
    ChemID
    StrtgyID
    Quantity
    Value
    Modified)
    Select InvntrySbLdgrChngeID
    DlHdrID
    DlDtlID
    ChildPrdctID
    StrtgyID
    VolumeChanged
    ValueChanged
    , 'N'
    of InventorySubLedgerChange
    where LastInChain = 'Y '.

    -updated column "Changed" of particular documents to 'Y' based on conditions

    Update #ActCde
    Changed the value = 'Y '.
    of #ActCde (nolock)
    Left Outer Join InventorySubledgerDetail ISD (nolock)
    on #ActCde.DlHdrID = DSI. DlDtlChmclDlDtlDlHdrID
    and #ActCde.DlDtlID = ISD. DlDtlChmclDlDtlID
    and #ActCde.ChemID = DSI. DlDtlChmclChmclChldPrdctID
    and #ActCde.StrtgyID = DSI. StrtgyID
    and the DSI. AccntngPrdID = @i_AccntngPrdID - variable parameter
    Where abs (#ActCde.Qty - isnull (ISD.) BeginningVolume, 0)) >.01
    or abs (#ActCde.Value - isnull (ISD.) BeginningValue, 0)) >.01
    or (abs(#ActCde.Qty) = 0 and)
    ABS(#ActCde.value) = 0 and
    ABS (isnull (ISD. BeginningVolume, 0)) = 0 and
    ABS (isnull (ISD. BeginningValue, 0)) = 0
    )

    Convertion of SQL:
    ===============
    I would like to do something like

    Select A.InvntrySbLdgrChngeID,
    A.DlHdrID,
    A.DlDtlID,
    A.ChemID,
    A.StrtgyID,
    A.Qty,
    A.Value,
    A.Changed
    Of
    (select InvntrySbLdgrChngeID
    DlHdrID
    DlDtlID
    ChildPrdctID AS ChemID
    StrtgyID
    VolumeChanged AS Qty,
    ValueChanged value have
    , 'N'
    of InventorySubLedgerChange
    where LastInChain = 'Y') A LEFT OUTER JOIN InventorySubledgerDetail B
    ON A.DlHdrID = B.DlDtlChmclDlDtlDlHdrID
    and A.DlDtlID = B.DlDtlChmclDlDtlID
    and A.ChemID = B.DlDtlChmclChmclChldPrdctID
    and A.StrtgyID = B.StrtgyID
    and B.AccntngPrdID = i_AccntngPrdID - parameter varibale
    Where abs (A.Qty - isnull(B.BeginningVolume,0)) >.01
    or abs (A.Value - isnull(B.BeginningValue,0)) >.01
    or (abs (A.Qty) = 0 and)
    ABS (A.value) = 0 and
    ABS (IsNull(B.BeginningVolume,0)) = 0 and
    ABS (IsNull(B.BeginningValue,0)) = 0
    )

    And I need to change the 'A.CHANGED' column value 'Y', based on the outer join, as is above T - SQL.

    IF this wont work so pls help me to another way to do this.

    in this regard, your help is appreciated.

    Thank you!

    SS

    Try this

    select #ActCde.InvntrySbLdgrChngeID
           , #ActCde.DlHdrID
           , #ActCde.DlDtlID
           , #ActCde.ChildPrdctID
           , #ActCde.StrtgyID
           , #ActCde.VolumeChanged
           , #ActCde.ValueChanged
           , case when abs(#ActCde.Qty - isnull(ISD.BeginningVolume,0)) > .01  or
                       abs(#ActCde.Value - isnull(ISD.BeginningValue,0)) > .01 or
                       (
                             abs(#ActCde.Qty)                   = 0 and
                             abs(#ActCde.Value)                 = 0 and
                             abs(isnull(ISD.BeginningVolume,0)) = 0 and
                             abs(isnull(ISD.BeginningValue,0))  = 0
                       )
                  then 'Y'
                  else 'N'
             end changed
      from InventorySubLedgerChange #ActCde
      Left Outer Join InventorySubledgerDetail ISD (nolock)
        on #ActCde.DlHdrID = ISD.DlDtlChmclDlDtlDlHdrID
       and #ActCde.DlDtlID= ISD.DlDtlChmclDlDtlID
       and #ActCde.ChemID = ISD.DlDtlChmclChmclChldPrdctID
       and #ActCde.StrtgyID = ISD.StrtgyID
       and ISD.AccntngPrdID = @i_AccntngPrdID - paramenter variable
     where LastInChain = "Y"
    
  • retrieve the records from the oracle sql query

    Hello

    I'm stuck with a requirement where I need to retrieve some recordset based on the conditions. I won't be able to produce the same data and table here, but I can explain the problem with the example statement:

    If col2 contains 'y' to any folder, then select only the records. Where, as if no line contains the value 'y' for col2 then retrieve all records.

    Database version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64 bit Production

    with temp (col1,col2)
    as
    (select level,decode(mod(level,2),0,'y',1,'n')
    from dual
    connect by level < 10)
    select * from temp;
    
    

    Please help, if possible through sql.

    Thank you

    Vikram

    Something like below... Considered as non-null column col2...

    with the temp (col1, col2)

    as

    (select level, decode (mod(level,2), 0, 'y', 1,' no))

    of the double

    connect by level<>

    Select * from temp

    WHERE col2 = NVL ((SELECT col2 FROM temp OÙ col2 = 'y' ET rownum = 1), col2);

  • SQL Query help find albums from sale

    Hi Experts,

    I have the following data and the need to find the book Top sold in each type.

    Book Type QTY

    20Help the3
    10Kitchen1
    5Navigation2
    30Help the4

    Please let me how can know we get this simple SQL help?

    Thank you

    Bharat

    Hello

    Bharat Hegde wrote:

    Hi all

    I tried to use Dense_rank as below. But it gives me the top selling books. I need high library in each type...

    This looks like a job for 'PARTITION BY type

    For example:

    WITH got_rnk AS

    (

    SELECT b.bid, b.type

    SUM (o.quantity) AS total_quantity

    DENSE_RANK () OVER ( PARTITION BY b.type

    ORDER OF SUM (o.quantity) / / DESC

    ) AS rnk

    B BOOK

    o order1

    WHERE b.bid = o.bid

    GROUP BY b.bid, b.type

    )

    SELECT total_quantity, type submission

    OF got_rnk

    WHERE rnk = 1

    ;

    . Aggregate functions (such as the SUM, above) are calculated before analytical functions, so an analytic function (such as DENSE_RANK above) may depend on an aggregate function; you don't need a separate subquery for that.

  • SQL Query Help (not working not properly)

    Hello everyone,

    I use JDeveloper 12.1.2.0.0. I do a two-way communication using 3 tables, with links between them (and using schema HR).

    In my example, I have something like:

    Departments, employees, and the SalaryByJobs (I created this table where it shows a departmentd id, employee id, salary).

    Whenever I click on one OR more departments, the employees up-to-date table by putting on the table, employees who belong to the selected department and the salaryByjob to put the jobs of the employees selected on the employees table.

    So it's something like this:

    The departments selected-> employees selected-> salarybyjbobs of these employees.

    My query used (in the view) has the following code:

    SELECT Employees.COMMISSION_PCT,

    Employees.DEPARTMENT_ID,

    Employees.EMAIL,

    Employees.EMPLOYEE_ID,

    Employees.FIRST_NAME,

    Employees.HIRE_DATE,

    Employees.JOB_ID,

    Employees.LAST_NAME,

    Employees.MANAGER_ID,

    Employees.PHONE_NUMBER,

    Employees.SALARY

    Employees EMPLOYEES

    WHERE (department_id IN (select * from THE (select cast (in_list(:variavel3) as mytableType) double) a))

    Since I use the links, the employees table does not show anything at the beginning, so I added this to my query used to go: OR nvl(:variavel3,0) = 0

    But now, whenever I try to select multiple lines, it gives me the invalid numbers and I don't understand why...

    It's only one line of code and it is not in the bean.

    Can someone help me?

    PS - The bean will Department by Department, adds the departments with ',' and for each Department, gets employees who belongs to them.

    My best regards,

    Frederico Barracha.

    The expression NVL (: variavel3, 0) = 0 is not correct. The data type of the return value of the NVL function is considered to be equal to the data type of the argument of 1 (that is, the data type of the variable binding: variavel3). You said that this variable contained a list separated by commas to ID, so the data type of the variable is VARCHAR2. As long as you compare the NVL expression of a number, you get 'Invalid number' exception, because Oracle expects a numeric data type on the left side of the comparison operator.

    To avoid the exception "Invalid number", you can modify the expression by using one of the following options:

    : variavel3 IS NULL

    NVL (: variavel3, ' *') = ' *'

    NVL (: variavel3, ' 0') = '0'

    Option 1, so the simplest and clearest.

    Dimitar

  • Dynamic recovery for the dynamic sql query

    Hi all

    I want to create a query dynamically and to fetch it in a dynamic cursor record... The structure of the record should be the same as that of the query...
    Can you suggest any method to do this.

    for example

    OPEN < dynamic news > TO < dynamic stmt >;
    LOOP
    FETCH < dynamic news > < DYNAMIC rec >;
    ---
    END LOOP;
    CLOSE < dynamic news >;

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Thank you
    Merz

    Published by: merz Sep 12, 2011 17:02

    Published by: merz Sep 12, 2011 17:03

    Merz says:

    How to declare the rec here dynamic? I wouldn't have the columns in the query in advance either.

    Is not possible. What you describe is called four dynamic sql type. For this type of synamic SQL, you use the DBMS_SQL package.

    SY.

  • Conditional display of interactive report based on the different SQL query

    Hello

    I have two drop-down list at the top of my page and below I have an interactive report.
    Based on the selection of the user from the drop-down list values, interactive report should change based on different SQL queries.

    Is it possible to have different SQL queries based on the drop-down list values and generate interactive report based on that?

    Thank you

    Hello

    You can't have IR based on function returning the query as you can have classic report

    But here is a workaround
    http://www.oracleapplicationexpress.com/tutorials/71

    Kind regards
    Jari

  • SQl query help please...

    Hello

    I have a requirement... can help you pleease

    I have a table with two columns called Doc R, Seq R

    Sampled data:
    Type          Doc R           Seq R
    --------        ---------        ------------
    R                R1               Null
    Q               Q1                R1
    R                R2               Null
    Q               Q2               R2
    R                R3               Null
    Q               Null              Null
    
    
    Now  if you see first two records R1 and R2 have corresponding Q2.....
    if you see R3 dont have Q values..
    
    Now i want the count of R3 like records where it does not have Corresponding Q values in ...
    
    any ideas please...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    Hello

    Another way, which could be more efficient (but less clear):

    WITH   got_grp         AS
    (
         SELECT     CASE WHEN rtype = 'Q' THEN seq_r ELSE doc_r END     AS grp
         ,     CASE WHEN rtype = 'Q' THEN 0     ELSE 1     END     AS r_val
         FROM     yourtable
         WHERE     rtype  IN ('Q', 'R')
    )
    SELECT       COUNT (COUNT (*))     AS grp_cnt
    FROM       got_grp
    GROUP BY  grp
    HAVING       COUNT (*)     = SUM (r_val)
    ;
    

    You have not said if a line where
    rtype = 'R' and doc_r has the value NULL is considered to be a match for a line where
    rtype = 'Q' and seq_r is NULL.

    In the application of Cyn, they are not a match.
    In the above query, they are.
    A query can be changed for a different result.

  • SQL query help

    Hello

    I have the table and professorid, studentid, classid.

    Please provide the sql code to find professor_id which hosts up to students.

    with t as)

    Select professor_id,

    ROW_NUMBER() over (order by count (distinct student_id) desc) rn

    from your_table

    Professor_id group

    )

    Select professor_id

    t

    where rn = 1

    /

    However, if there is a tie and a teacher number max of students has more meanings will select one of them. If you want that all teachers use:

    with t as)

    Select professor_id,

    DENSE_RANK() over (order by count (distinct student_id) desc) rn

    from your_table

    Professor_id group

    )

    Select professor_id

    t

    where rn = 1

    /

    SY.

Maybe you are looking for