SQL query for empty string

I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.

I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.

Thanks in advance for your help,

Jim

Jim,

Just to be sure, have you used 'is' instead of '=' in this command?

This makes all the difference in this command.

Cerati

Tags: NI Software

Similar Questions

  • Single SQL query for the analysis of the date of customs declaration under the table of Stock codes

    Dear all,


    Please tell us a single SQL query for the below,

    We have a Table of Stock as shown below,

    STOCK_TABLE

     

    ITEM_CODE

    (item code)

    BAT_NO

    (lot no.)

    TXN_CODE

    (transaction code)

    DOC_NO

    (number)

    BOE_DT

    (date of the customs declaration)

    I1

    B1

    I1

    I2

    I3

    B70

    I4

    B80

    I5

    B90

    T102

    1234

    JULY 2, 2015

    I6

    B100

    We have to find the date of customs declaration (i.e. the date when the items have come under this particular table) for items that are not attached to any document (that is, who have TXN_CODE, DOC_NO and BOE_DT fields with a NULL value).

    For each item in the table of actions, which is not attached to any document, the customs declaration date is calculated as follows.

    1. If (code section, lot number) combination is present under HISTORY_TABLE, the date of customs declaration will receive the UPDT_DT, the transaction code (TXN_CODE) is an IN or transactions (which can be analyzed from the TRANSACTIONS table).

    2. If (code section, lot number) combination is NOT currently at the HISTORY_TABLE (or) the transaction code respective to item - batch number combination code is an operation then customs declaration date will be the date of the document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD that contains the element of that particular lot.

  • If the case 1 and case 2 fails, our customs declaration date will be the last date of document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD containing that particular item and the BAT_NO in expected results will be that corresponding to this document, as appropriate, to another NULL.

  • If the case 1 or case 2 is successful, the value of the last field (in the output expected, shown further below) BATCH_YN will be 'Y', because it fits the lot. Otherwise it will be 'n'.
  • HISTORY_TABLE

     

    ITEM_CODE

    BAT_NO

    TXN_CODE

    DOC_NO

    UPDT_DT

    I1

    B1

    T1

    1234

    JANUARY 3, 2015

    I1

    B20

    T20

    4567

    MARCH 3, 2015

    I1

    B30

    T30

    7890

    FEBRUARY 5, 2015

    I2

    B40

    T20

    1234

    JANUARY 1, 2015

    TRANSACTION

     

    TXN_CODE

    TXN_TYPE

    T1

    IN

    T20

    OFF

    T30

    ALL THE

    T50

    IN

    T80

    IN

    T90

    IN

    T60

    ALL THE

    T70

    ALL THE

    T40

    ALL THE

    IN_TABLE_HEAD_1

     

    H1_SYS_ID

    (primary key)

    TXN_CODE

    DOC_NO

    DOC_DATE

    H1ID1

    T1

    1234

    JANUARY 1, 2015

    H1ID2

    T70

    1234

    FEBRUARY 1, 2015

    IN_TABLE_ITEM_1

     

    I1_SYS_ID

    H1_SYS_ID

    (foreign key referencing H1_SYS_ID in IN_TABLE_HEAD_1)

    ITEM_CODE

    I1ID1

    H1ID1

    I1

    I1ID2

    H1ID1

    I100

    I1ID3

    H1ID2

    I3

    IN_TABLE_BATCH_1

     

    B1_SYS_ID

    TXN_CODE                DOC_NO

    (now in IN_TABLE_HEAD_1)

    BAT_NO

    B1ID1

    T1

    1234

    B1 / can be empty

    B1ID2

    T70

    1234

    B70

    IN_TABLE_HEAD_2

     

    H2_SYS_ID

    (primary key)

    TXN_CODE

    DOC_NO

    DOC_DATE

    H2ID1

    T30

    4567

    FEBRUARY 3, 2015

    H2ID2

    T60

    1234

    JANUARY 3, 2015

    IN_TABLE_ITEM_2

     

    I2_SYS_ID

    H2_SYS_ID

    (foreign key referencing H2_SYS_ID in IN_TABLE_HEAD_2)

    ITEM_CODE

    I2ID1

    H2ID1

    I1

    I2ID2

    H2ID1

    I200

    I2ID3

    H2ID2

    I2

    IN_TABLE_BATCH_2

     

    B2_SYS_ID

    I2_SYS_ID

    (foreign key referencing I2_SYS_ID in IN_TABLE_ITEM_2)

    BAT_NO

    B2ID1

    I2ID1

    B30 / null

    B2ID2

    I2ID2

    B90

    B2ID2

    I2ID3

    B60

    IN_TABLE_HEAD_3

     

    H3_SYS_ID

    (primary key)

    TXN_CODE

    DOC_NO

    DOC_DATE

    H3ID1

    T50

    1234

    JANUARY 2, 2015

    H3ID2

    T80

    1234

    JANUARY 3, 2015

    H3ID3

    T90

    1234

    JANUARY 4, 2015

    H3ID4

    T40

    1234

    AUGUST 5, 2015

    IN_TABLE_ITEM_3

     

    I3_SYS_ID

    H3_SYS_ID

    (foreign key referencing H3_SYS_ID in IN_TABLE_HEAD_3)

    ITEM_CODE

    BAT_NO

    I3ID1

    H31D1

    I2

    B50

    I3ID2

    H3ID2

    I4

    B40

    I3ID3

    H3ID3

    I4

    I3ID4

    H3ID4

    I6

    There is no IN_TABLE_BATCH_3

    Please find below the expected results.

    OUTPUT

     

    ITEM_CODE

    BAT_NO

    TXN_CODE

    DOC_NO

    BOE_DT

    BATCH_YN

    I1

    B1

    T1

    1234

    JANUARY 3, 2015

    THERE

    I1

    B30

    T30

    7890

    FEBRUARY 5, 2015

    N

    I2

    B60

    T60

    1234

    JANUARY 3, 2015

    N

    I3

    B70

    T70

    1234

    FEBRUARY 1, 2015

    THERE

    I4

    T90

    1234

    JANUARY 4, 2015

    N

    I6

    T40

    1234

    AUGUST 5, 2015

    N

    Controls database to create the tables above and insert the records.

    CREATE TABLE stock_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), boe_dt DATE );

    INSERT EN stock_table

       VALUES ('I1', 'B1', '', '', '');

    INSERT EN stock_table

       VALUES ('I1', '', '', '', '');

    INSERT IN stock_table

       VALUES ('I2', '', '', '', '');

    INSERT EN stock_table

       VALUES ('I3', 'B70', '', '', '');

    INSERT EN stock_table

       VALUES ('I4', 'B80', '', '', '');

    INSERT EN stock_table

       VALUES ('I5', 'B90', 'T102', '1234', '02-JUL-2015');

    INSERT EN stock_table

       VALUES ('I6', 'B100', '', '', '');

    SELECT *

    FROM stock_table




     

    CREATE TABLE history_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), updt_dt DATE );

    INSERT IN history_table

       VALUES ('I1', 'B1', 'T1', '1234', '03-JAN-2015');

    INSERT IN history_table

       VALUES ('I1', 'B20', 'T20', '4567', '03-MAR-2015');

    INSERT IN history_table

       VALUES ('I1', 'B30', 'T30', '7890', '05-FEB-2015');

    INSERT IN history_table

       VALUES ('I2', 'B40', 'T20', '1234', '01-JAN-2015');

    SELECT *

    FROM history_table




     

    CREATE TABLE transaction1()txn_code VARCHAR()80),txn_type VARCHAR()80));


    INSERT INTO transaction1

       VALUES ('T1', 'IN');


    INSERT INTO transaction1

       VALUES ('T20', 'OUT');

    INSERT INTO transaction1

       VALUES ('T30', 'ALL');

    INSERT INTO transaction1

       VALUES ('T40', 'ALL');

    INSERT INTO transaction1

       VALUES ('T50', 'IN');

    INSERT INTO transaction1

       VALUES ('T60', 'ALL');

    INSERT INTO transaction1

       VALUES ('T70', 'ALL');

    INSERT INTO transaction1

       VALUES ('T80', 'IN');

    INSERT INTO transaction1

       VALUES ('T90', 'IN');

    SELECT *

    FROM transaction1




     

    CREATE TABLE in_table_head_1()h1_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), doc_dt DATE );

    CREATE TABLE in_table_head_2()h2_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), doc_dt DATE );

    CREATE TABLE in_table_head_3()h3_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),

    doc_no VARCHAR2 (80), doc_dt DATE );

     

    INSERT IN in_table_head_1

       VALUES ('H1ID1', 'T1', '1234', '01-JAN-2015');

    INSERT IN in_table_head_1

       VALUES ('H1ID2', 'T70', '1234', '01-FEB-2015');

    INSERT IN in_table_head_2

       VALUES ('H2ID1', 'T30', '4567', '03-FEB-2015');

    INSERT IN in_table_head_2

       VALUES ('H2ID2', 'T60', '1234', '03-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID1', 'T50', '1234', '02-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID2', 'T80', '1234', '03-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID3', 'T90', '1234', '05-JAN-2015');

    INSERT IN in_table_head_3

       VALUES ('H3ID4', 'T40', '1234', '05-AUG-2015');




     

    CREATE TABLE in_table_item_1()i1_sys_id VARCHAR2()80) PRIMARY KEY,

    h1_sys_id VARCHAR2 (80) REFERENCES in_table_head_1()h1_sys_id),item_code VARCHAR2()80));

    CREATE TABLE in_table_item_2()i2_sys_id VARCHAR2()80) PRIMARY KEY,

    h2_sys_id VARCHAR2 (80) REFERENCES in_table_head_2()h2_sys_id),item_code VARCHAR2()80));

    CREATE TABLE in_table_item_3(i3_sys_id VARCHAR2(80) PRIMARY KEY,

    h3_sys_id VARCHAR2 (80) REFERENCES in_table_head_3()h3_sys_id),item_code VARCHAR2()80),

    bat_no VARCHAR2 (80));

     

    INSERT IN in_table_item_1

       VALUES ('I1ID1', 'H1ID1', 'I1');

    INSERT IN in_table_item_1

       VALUES ('I1ID2', 'H1ID1', 'I100');

    INSERT IN in_table_item_1

       VALUES ('I1ID3', 'H1ID2', 'I3');

    INSERT IN in_table_item_2

       VALUES ('I2ID1', 'H2ID1', 'I1');

    INSERT IN in_table_item_2

       VALUES ('I2ID2', 'H2ID1', 'I200');

    INSERT IN in_table_item_2

       VALUES ('I2ID3', 'H2ID2', 'I2');

    INSERT IN in_table_item_3

       VALUES ('I3ID1', 'H3ID1', 'I2','B50');

    INSERT IN in_table_item_3

       VALUES ('I3ID2', 'H3ID2', 'I4','B40');

    INSERT IN in_table_item_3

       VALUES ('I3ID3', 'H3ID3', 'I4','');

    INSERT IN in_table_item_3

       VALUES ('I3ID4', 'H3ID4', 'I6','');

    SELECT *

    FROM in_table_item_1

    SELECT *

    FROM in_table_item_2

    SELECT *

    FROM in_table_item_3




     

    CREATE TABLE in_table_batch_1()b1_sys_id VARCHAR2()80) PRIMARY KEY,

    txn_code VARCHAR2 (80), doc_no VARCHAR2 (80), bat_no VARCHAR2 (80));

    CREATE TABLE in_table_batch_2()b2_sys_id VARCHAR2()80) PRIMARY KEY,

    i2_sys_id VARCHAR2 (80) REFERENCES in_table_item_2()i2_sys_id),bat_no VARCHAR2()80));

     

    INSERT IN in_table_batch_1

       VALUES ('B1ID1', 'T1', '1234', 'B1');

    INSERT IN in_table_batch_1

       VALUES ('B1ID2', 'T70', '1234', 'B70');

    INSERT IN in_table_batch_2

       VALUES ('B2ID1', 'I2ID1', 'B30');

    INSERT IN in_table_batch_2

       VALUES ('B2ID2', 'I2ID2', 'B90');

    INSERT IN in_table_batch_2

       VALUES ('B2ID3', 'I2ID3', 'B60');

    Please advise a solution for the same.

    Thank you and best regards,

    Séverine Suresh

    very forced (question subfactoring used to allow easy testing/verification - could work with these test data only)

    with

    case_1 as

    (select s.item_code,

    s.bat_no,

    h.txn_code,

    h.doc_no,

    h.updt_dt boe_dt,

    cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.

    cases where h.txn_code is not null

    and h.doc_no is not null

    and h.updt_dt is not null

    then 'case 1' '.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, boe_dt

    of w_stock_table

    where bat_no is null

    or txn_code is null

    or doc_no is null

    or boe_dt is null

    ) s

    left outer join

    w_history_table h

    On s.item_code = h.item_code

    and s.bat_no = h.bat_no

    and exists (select null

    of w_transaction1

    where txn_code = nvl (s.txn_code, h.txn_code)

    and txn_type in ('IN', 'ALL')

    )

    ),

    case_2 as

    (select s.item_code,

    NVL (s.bat_no, h.bat_no) bat_no.

    NVL (s.txn_code, h.txn_code) txn_code.

    NVL (s.doc_no, h.doc_no) doc_no.

    NVL (s.boe_dt, h.updt_dt) updt_dt.

    cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.

    cases where h.txn_code is not null

    and h.doc_no is not null

    and h.updt_dt is not null

    then 'case 2'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, boe_dt

    of case_1

    where refers_to is null

    ) s

    left outer join

    w_history_table h

    On s.item_code = h.item_code

    and exists (select null

    of w_transaction1

    where txn_code = nvl (s.txn_code, h.txn_code)

    and txn_type in ('IN', 'ALL')

    )

    and not exists (select null

    of case_1

    where item_code = h.item_code

    and bat_no = h.bat_no

    and txn_code = h.txn_code

    and doc_no = h.doc_no

    and updt_dt = h.updt_dt

    )

    ),

    case_31 as

    (select s1.item_code,

    NVL (S1.bat_no, W1.bat_no) bat_no.

    NVL (S1.txn_code, W1.txn_code) txn_code.

    NVL (S1.doc_no, W1.doc_no) doc_no.

    NVL (S1.updt_dt, W1.doc_dt) updt_dt.

    cases where s1.bat_no = w1.bat_no then 'Y' else ' n end batch_yn.

    cases where w1.txn_code is not null

    and w1.doc_no is not null

    and w1.doc_dt is not null

    then "case 31'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to

    of case_2

    where refers_to is null

    ) s1

    left outer join

    (select i1.item_code, h1.txn_code, h1.doc_no, h1.doc_dt, b1.bat_no

    of w_in_table_item_1 i1

    inner join

    w_in_table_head_1 h1

    On i1.h1_sys_id = h1.h1_sys_id

    inner join

    w_in_table_batch_1 b1

    On h1.txn_code = b1.txn_code

    and h1.doc_no = b1.doc_no

    ) w1

    On s1.item_code = w1.item_code

    ),

    case_32 as

    (select s2.item_code,

    NVL (S2.bat_no, W2.bat_no) bat_no.

    NVL (S2.txn_code, W2.txn_code) txn_code.

    NVL (S2.doc_no, W2.doc_no) doc_no.

    NVL (S2.updt_dt, W2.doc_dt) updt_dt.

    cases where s2.bat_no = w2.bat_no then 'Y' else ' n end batch_yn.

    cases where w2.txn_code is not null

    and w2.doc_no is not null

    and w2.doc_dt is not null

    then "case 32'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to

    of case_2

    where refers_to is null

    ) s2

    left outer join

    (select i2.item_code, h2.txn_code, h2.doc_no, h2.doc_dt, b2.bat_no

    of w_in_table_item_2 i2

    inner join

    w_in_table_head_2 h2

    On i2.h2_sys_id = h2.h2_sys_id

    inner join

    w_in_table_batch_2 b2

    On i2.i2_sys_id = b2.i2_sys_id

    ) w2

    On s2.item_code = w2.item_code

    ),

    case_33 as

    (select s3.item_code,

    w3.bat_no,

    NVL (S3.txn_code, w3.txn_code) txn_code.

    NVL (S3.doc_no, w3.doc_no) doc_no.

    NVL (S3.updt_dt, w3.doc_dt) updt_dt.

    cases where s3.bat_no = w3.bat_no then 'Y' else ' n end batch_yn.

    cases where w3.txn_code is not null

    and w3.doc_no is not null

    and w3.doc_dt is not null

    then "case 33'.

    end refers_to

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to

    of case_2

    where refers_to is null

    ) s3

    left outer join

    (select i3.item_code, h3.txn_code, h3.doc_no, h3.doc_dt, i3.bat_no

    of w_in_table_item_3 i3

    inner join

    w_in_table_head_3 h3

    On i3.h3_sys_id = h3.h3_sys_id

    ) w3

    On s3.item_code = w3.item_code

    )

    Select item_code, bat_no, txn_code, doc_no, boe_dt, batch_yn

    of case_1

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_2

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn,

    ROW_NUMBER() over (partition by item_code of updt_dt desc order) rn

    from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_31

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_32

    where refers_to is not null

    Union of all the

    Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn

    of case_33

    where refers_to is not null

    )

    )

    where rn = 1

    ITEM_CODE BAT_NO TXN_CODE DOC_NO BOE_DT BATCH_YN
    I1 B1 T1 1234 JANUARY 3, 2015 THERE
    I1 B30 T30 7890 FEBRUARY 5, 2015 N
    I2 B60 T60 1234 JANUARY 3, 2015 N
    I3 B70 T70 1234 FEBRUARY 1, 2015 THERE
    I4 - T90 1234 JANUARY 5, 2015 N
    I6 - T40 1234 AUGUST 5, 2015 N

    Concerning

    Etbin

  • SQL query for the apex report

    Hi team,

    For example if I have a demo table with 4 columns (A, B, C, D) DEMO.

    I want a report on this table, such that the report contains the headers and the Details section.

    For each unique combination of (A, B) I must first of all show header based on the header information I want to display the detailed section.
    In my header section I want to display 2 columns (A, B) that are common to the detailed section. Remaining 2 columns in the detailed section.


    Here is an example: -.

    A B C D
    1 5 9 3
    1 5P8
    1 5 P O
    1-5-9
    1 8 9
    1     D     *     /
    2 8 33 P
    2 P O O
    2 P L L

    YOU WILL SEE
    A AND B
    1 5

    C D
    9 3
    P 8
    P O


    A AND B
    1 D

    C D
    5 9
    8 9
    *     /



    A AND B
    2 P

    C D
    8 33
    O O
    L L

    Please suggest the solution (sql query) for above the problem and how to nest gernerated headers dynamically in the report area.
    I use APEX 4.0
    Any position in this regard is very significant.

    Thanks and greetings
    Rajendra

    Try this:

    SQL> select * from tab;
    1 5 9 3
    1 5 P 8
    1 5 P O
    1 D 5 9
    1 D 8 9
    1 P 8 3
    1 P O O
    
    7 rows selected.
    
    SQL> select a,b from
    (select r,a,b from
    ( select to_char(rownum)||'a' r, 'A' a,'B' b from
            (select distinct a, b from tab order by a,b))
            union
    ( select to_char(rownum)||'c' r, 'C' c,'D' d from
            (select distinct a, b from tab order by a,b))
    union
    ( select to_char(rownum)||'b' r, a,b from
    (select distinct a, b from tab order by a,b))
    union
    select parent.r, tab.c, tab.d from
    ( select to_char(rownum)||'d' r, a,b from
    (select distinct a, b from tab order by a,b)) parent ,
    tab
    where parent.a=tab.a and
    parent.b=tab.b
    ) order by r
    ;
    A B
    1 5
    C D
    9 3
    P 8
    P O
    A B
    1 D
    C D
    5 9
    8 9
    A B
    1 P
    C D
    8 3
    O O
    
  • SQL query for the mapping of a set of prizes to a group of classrooms

    Hi all

    I use Oracle database 11g Release 2.

    I have the following data set:

    Classrooms
    ClassId ClassName ability group
    ------ ----------------------------------------------      --------------     -----------
    Babbage/software Engg Lab 1 24 1
    Basement 2 - block PG 63 1
    3 1 56 1 class
    Class 4 1 24 10
    Class 5 1 24 11
    Class 6 1 35 12
    7 13 42 1 class
    8 14 42 1 class
    9 15 42 1 class
    10 2 35 1 class
    11 3 35 1 class
    12 4 35 1 classroom
    13 5 35 1 class
    14 6 25 1 class
    15 7 25 1 class
    16 1 24 8 class
    17 9 24 1 class
    18 control Sys Lab 1 24
    19 dig & Embd Sys Lab 20 1
    20 PSD & Comm 20 1 Lab
    21 electromechanical system Lab 28 1
    Farabi 22/Web Tech Lab 1 36
    23 gen purpose Lab 40 1
    Shirazi/24dB Tech Lab 1 36
    ADV 25 elect Lab 30 2
    26 16 42 2 class
    27 17 49 2 class
    28 18 56 2 class
    29 19 42 2 class
    30 20 49 2 class
    Class 31 21 35 3
    32 22 35 3 class
    33 20 3 MDA lab

    DegreeBatches
    BatchId BatchName force
    ---------------     ----------------------- --------------
    1 BIT - 11 79
    2 BIT - 12 28
    3 BS (CS)-1 35
    4 BS (CS) 78-2
    5 BE (SE)-1 69
    6. BE (SE) 84-2
    7 BE (SE) 64-3
    8 84 BYTČA-7
    9 43 BYTČA-8
    BEE-1 10, 112
    11 151 BEE-2
    BEE-3 12, 157
    13 BEE-4 157

    I want to map a combination of batch of degree for a class rooms group of such distance that they make full use of the maximum capacity of the class rooms within a group (ideally), or as close to this as possible. Can it be done with a SQL query?

    Any response will be appreciated.

    The SQL Scripts to generate the required tables and populate data is less to:
    CREATE TABLE classrooms (ClassId NUMBER, ClassName VARCHAR2 (50), capacity NUMBER, group NUMBER);
    INSERT INTO the classrooms of the VALUES (1, "Babbage/software Engg Lab', 24, 1");
    INSERT INTO the classrooms of the VALUES (2, 'basement - PG block', 63, 1);
    INSERT INTO the classrooms of the VALUES (3, '1 class room', 56, 1);
    INSERT INTO the classrooms of the VALUES (4, '10 class room', 24, 1);
    INSERT INTO the classrooms of the VALUES (5, '11 class room', 24, 1);
    INSERT INTO the classrooms of the VALUES (6, 'class room 12', 35, 1);
    INSERT INTO the classrooms of the VALUES (7, 'class room 13', 42, 1);
    INSERT INTO the classrooms of the VALUES (8, 'class room 14', 42, 1);
    INSERT INTO the classrooms of the VALUES (9, '15 'class, 42, 1);
    INSERT INTO the classrooms of the VALUES (10, 'class 2', 35, 1);
    INSERT INTO the classrooms of the VALUES (11, 'class room 3', 35, 1);
    INSERT INTO the classrooms of the VALUES (12, 'class room 4', 35, 1);
    INSERT INTO the classrooms of the VALUES (13, 'class room 5', 35, 1);
    INSERT INTO the classrooms of the VALUES (14, 'class room 6', 25, 1);
    INSERT INTO the classrooms of the VALUES (15, '7 class room', 25, 1);
    INSERT INTO the classrooms of the VALUES (16, 'class Room 8', 24, 1);
    INSERT INTO the classrooms of the VALUES (17, 'class room 9', 24, 1);
    INSERT INTO the classrooms of the VALUES (18, 'Control Sys Lab', 24, 1);
    INSERT INTO the classrooms of the VALUES (19, 'Dig & Embd Sys Lab', 20, 1);
    INSERT INTO the classrooms of the VALUES (20, 'DSP & Comm Lab', 20, 1);
    INSERT INTO the classrooms of the VALUES (21, 'system ELECTROMECHANICAL Lab', 28, 1);
    INSERT INTO the classrooms of the VALUES (22, ' Farabi/Web Tech Lab', 36, 1);
    INSERT INTO the classrooms of the VALUES (23, 'Gen purpose Lab', 40, 1);
    INSERT INTO the classrooms of the VALUES (24, ' Shirazi/DB Tech Lab', 36, 1);
    INSERT INTO the classrooms of the VALUES (25, 'Elected Adv Lab', 30, 2);
    INSERT INTO the classrooms of the VALUES (26, 'class room 16', 42, 2);
    INSERT INTO the classrooms of the VALUES (27, 'class room 17', 49, 2);
    INSERT INTO the classrooms of the VALUES (28, '18 'class, 56, 2);
    INSERT INTO the classrooms of the VALUES (29, '19 'class, 42, 2);
    INSERT INTO the classrooms of the VALUES (30, 'class room 20', 49, 2);
    INSERT INTO the classrooms of the VALUES (31, 'class room 21', 35, 3);
    INSERT INTO the classrooms of the VALUES (32, 'room 22', 35, 3);
    INSERT INTO the classrooms of the VALUES (33, 'MDA Lab', 20, 3);

    CREATE TABLE DegreeBatches (BatchId NUMBER, BatchName VARCHAR2 (50), membership NUMBER);
    INSERT INTO DegreeBatches VALUES(1,'BIT-11',79);
    INSERT INTO DegreeBatches VALUES(2,'BIT-12',28);
    INSERT INTO DegreeBatches VALUES (3, 'BS (CS) - 1', 35);
    INSERT INTO DegreeBatches VALUES (4, 'BS (CS) - 2', 78);
    INSERT INTO DegreeBatches VALUES (5,'BE (SE) - 1', 69);
    INSERT INTO DegreeBatches VALUES (6,'BE (SE) - 2', 84);
    INSERT INTO DegreeBatches VALUES (7,'BE (SE) - 3', 64);
    INSERT INTO DegreeBatches VALUES(8,'BICSE-7',84);
    INSERT INTO DegreeBatches VALUES(9,'BICSE-8',43);
    INSERT INTO DegreeBatches VALUES(10,'BEE-1',112);
    INSERT INTO DegreeBatches VALUES(11,'BEE-2',151);
    INSERT INTO DegreeBatches VALUES(12,'BEE-3',157);
    INSERT INTO DegreeBatches VALUES(13,'BEE-4',157);

    Best regards
    Bilal

    Published by: Bilal on December 27, 2012 09:52

    Published by: Bilal on December 27, 2012 10:07

    Bilal, thanks for the nice problem! Another possibility to double check is to write a small PL/SQL function that returns 1 if a duplicate id is found, then equate to 0: "NUMBER of RETURN of Duplicate_Token_Found (p_str_main in VARCHAR2, p_str_trial VARCHAR2). It should analyze the second string and could use p_str_main LIKE '%', | l_id | ', %' for each id. In any case, the query complete (without that) is given below:

    Solution with names
    SQL> WITH rsf_itm (con_id, max_weight, nxt_id, lev, tot_weight, tot_profit, path, root_id, lev_1_id) AS (
      2  SELECT c.id,
      3         c.max_weight,
      4         i.id,
      5         0,
      6         i.item_weight,
      7         i.item_profit,
      8         ',' || i.id || ',',
      9         i.id,
     10         0
     11    FROM items i
     12   CROSS JOIN containers c
     13   UNION ALL
     14  SELECT r.con_id,
     15         r.max_weight,
     16         i.id,
     17         r.lev + 1,
     18         r.tot_weight + i.item_weight,
     19         r.tot_profit + i.item_profit,
     20         r.path || i.id || ',',
     21         r.root_id,
     22         CASE WHEN r.lev = 0 THEN i.id ELSE r.nxt_id END
     23    FROM rsf_itm r
     24    JOIN items i
     25      ON i.id > r.nxt_id
     26     AND r.tot_weight + i.item_weight <= r.max_weight
     27   ORDER BY 1, 2
     28  ) SEARCH DEPTH FIRST BY nxt_id SET line_no
     29  , rsf_con (nxt_con_id, nxt_line_no, con_path, itm_path, tot_weight, tot_profit, lev) AS (
     30  SELECT con_id,
     31         line_no,
     32         To_Char(con_id),
     33         ':' || con_id || '-' || (lev + 1) || ':' || path,
     34         tot_weight,
     35         tot_profit,
     36         0
     37    FROM rsf_itm
     38   UNION ALL
     39  SELECT r_i.con_id,
     40         r_i.line_no,
     41         r_c.con_path || ',' || r_i.con_id,
     42         r_c.itm_path ||  ':' || r_i.con_id || '-' || (r_i.lev + 1) || ':' || r_i.path,
     43         r_c.tot_weight + r_i.tot_weight,
     44         r_c.tot_profit + r_i.tot_profit,
     45         r_c.lev + 1
     46    FROM rsf_con r_c
     47    JOIN rsf_itm r_i
     48      ON r_i.con_id > r_c.nxt_con_id
     49   WHERE r_c.itm_path NOT LIKE '%,' || r_i.root_id || ',%'
     50     AND r_c.itm_path NOT LIKE '%,' || r_i.lev_1_id || ',%'
     51     AND r_c.itm_path NOT LIKE '%,' || r_i.nxt_id || ',%'
     52  )
     53  , paths_ranked AS (
     54  SELECT itm_path || ':' itm_path, tot_weight, tot_profit, lev + 1 n_cons,
     55         Rank () OVER (ORDER BY tot_profit DESC) rnk,
     56         Row_Number () OVER (ORDER BY tot_profit DESC) sol_id
     57    FROM rsf_con
     58  ), best_paths AS (
     59  SELECT itm_path, tot_weight, tot_profit, n_cons, sol_id
     60    FROM paths_ranked
     61   WHERE rnk = 1
     62  ), row_gen AS (
     63  SELECT LEVEL lev
     64    FROM DUAL
     65  CONNECT BY LEVEL <= (SELECT Count(*) FROM items)
     66  ), con_v AS (
     67  SELECT  b.itm_path, r.lev con_ind, b.sol_id, b.tot_weight, b.tot_profit,
     68          Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev - 1) + 1,
     69            Instr (b.itm_path, ':', 1, 2*r.lev) - Instr (b.itm_path, ':', 1, 2*r.lev - 1) - 1)
     70             con_nit_id,
     71          Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev) + 1,
     72            Instr (b.itm_path, ':', 1, 2*r.lev + 1) - Instr (b.itm_path, ':', 1, 2*r.lev) - 1)
     73             itm_str
     74    FROM best_paths b
     75    JOIN row_gen r
     76      ON r.lev <= b.n_cons
     77  ), con_split AS (
     78  SELECT itm_path, con_ind, sol_id, tot_weight, tot_profit,
     79         Substr (con_nit_id, 1, Instr (con_nit_id, '-', 1) - 1) con_id,
     80         Substr (con_nit_id, Instr (con_nit_id, '-', 1) + 1) n_items,
     81         itm_str
     82    FROM con_v
     83  ), itm_v AS (
     84  SELECT  c.itm_path, c.con_ind, c.sol_id, c.con_id, c.tot_weight, c.tot_profit,
     85          Substr (c.itm_str, Instr (c.itm_str, ',', 1, r.lev) + 1,
     86            Instr (c.itm_str, ',', 1, r.lev + 1) - Instr (c.itm_str, ',', 1, r.lev) - 1)
     87             itm_id
     88    FROM con_split c
     89    JOIN row_gen r
     90      ON r.lev <= c.n_items
     91  )
     92  SELECT v.sol_id,
     93         v.tot_weight s_wt, v.tot_profit s_pr, c.id c_id, c.name c_name, c.max_weight m_wt,
     94         Sum (i.item_weight) OVER (PARTITION BY v.sol_id, c.id) c_wt,
     95         i.id i_id, i.name i_name, i.item_weight i_wt, i.item_profit i_pr
     96    FROM itm_v v
     97    JOIN containers c
     98      ON c.id = To_Number (v.con_id)
     99    JOIN items i
    100      ON i.id = To_Number (v.itm_id)
    101   ORDER BY sol_id, con_id, itm_id
    102  /
    
        SOL_ID S_WT S_PR  C_ID C_NAME          M_WT C_WT  I_ID I_NAME     I_WT I_PR
    ---------- ---- ---- ----- --------------- ---- ---- ----- ---------- ---- ----
             1  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     3 BSCS-2       35   35
                                                             5 BEE-4        50   50
             2  255  255     1 SEECS UG Block   100   95     4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   70     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
             3  255  255     1 SEECS UG Block   100  100     3 BSCS-2       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     1 BIT-10       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
             4  255  255     1 SEECS UG Block   100  100     3 BSCS-2       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     1 BIT-10       35   35
                                                             5 BEE-4        50   50
             5  255  255     1 SEECS UG Block   100   95     2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   70     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
             6  255  255     1 SEECS UG Block   100  100     2 BIT-11       40   40
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     1 BIT-10       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
             7  255  255     1 SEECS UG Block   100  100     2 BIT-11       40   40
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     1 BIT-10       35   35
                                                             5 BEE-4        50   50
             8  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     3 BSCS-2       35   35
                                                             5 BEE-4        50   50
             9  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            10  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   65     2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
            11  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   65     4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            12  255  255     1 SEECS UG Block   100   95     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
            13  255  255     1 SEECS UG Block   100   95     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            14  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
    
    98 rows selected.
    
    Elapsed: 00:00:01.42
    

    Published by: BrendanP on January 20, 2013 11:25
    I found the need to deduplicate regular expression:

    AND RegExp_Instr (r_c.itm_path | r_i.path, ',(\d+),.*?,\1,') = 0)

  • SQL query for the region of the tree

    Hello

    I was wondering if someone is able to help me work on a SQL query, to format the data in the table required in a part of the tree... I've never used a tree and I'm fighting to get the right data (if possible).

    The data in the table looks like this:

    data.PNG

    I want to put it in a tree, using level 1 level6 with a final layout that would look like this:

    tree.PNG

    As you can see, the data are formatted in level6 down in the tree, but are filled in the table from level 1. Not all of the columns will be filled, so level2 for anyone 4 (France) is the equivalent of level in the tree like level6 to person 1 (Spain).

    This is Apex 4.2.5

    Oracle 11.2.0.3.0

    Sample data:

    CREATE TABLE employees
       ( employee VARCHAR2(100),
         level1 VARCHAR2(100),
         level2 VARCHAR2(100),
         level3 VARCHAR2(100),
         level4 VARCHAR2(100),
         level5 VARCHAR2(100),
         level6 VARCHAR2(100)   
       );
    
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person1','Team One','Recruitment','Human Resources','Fictituous Company','Murcia','Spain');
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person2','Team Four','Testing','IT','Big Corporate','Hanover','Germany');
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person3','Big Corporate','Hanover','Germany', null, null, null);
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person4','Brittany','France', null, null, null, null);
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person5','Team Three','Testing','IT','Big Corporate','Hanover','Germany');
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person6','Public Relations','Government Agency','Brittany','France', null, null);
    
    

    Added example given.

    Hello

    Apex-user wrote:

    Thanks Frank, this is a good example, I can work with that! Your assumptions are correct.

    A question I came, however, is that I have a data segment that comes across poorly formatted so to speak... where only the lower levels (1-2, etc.) have been filled from the bottom up.

    An example of this data would be:

    1. INSERT INTO employees (employee, level 1, 2, level3, level4, level5, level6) VALUES ('Person7', 'One Team', 'Test', null, null, null, null);

    As you can see that if you rerun the select, the test team is now duplicated, both at the level of the root in the tree as it should.

    You are not sure if the sql can be adjusted to account for this, or if it's too hard?

    It is obviously a question of data and I am trying to solve this separately (extracted data from another system out of my control).

    Thank you!

    Sorry, I'm confused.

    You say that my assumptions were correct.  What includes supported that "If test ' occurs under 'IT' in a row, then the extent of the 'Testing' occurs, it must be under"IT "?  Right after you say that assumptions are correct, you give an example where 'Testing' occurs under 'IT' to a single line, but it is not less 'IT' to another line and where is 'One Team' under 'Testing' in a line, but is 'One Team' under 'Recruitment' in another row.

    When a situation like this occurs, how you cope?  Whenever you have a problem, please post the exact results you want from the given sample data, and an explanation of how you get these results.  If you don't know about what would be the ideal results, or if you are flexible on the exact results, then at least give an example and explain your reasons.

    Maybe you want to change the got_parent of subquery like this:

    WITH unpivoted_data AS

    (

    SELECT *.

    Employees

    UNPIVOT (node_name

    FOR lvl (level1 AS 1

    level2 AS 2

    level3 AS 3

    level4 AS 4

    level5 AS 5

    level6 AS-6

    )

    )

    )

    got_parent AS

    (

    SELECT c.node_name

    MIN (p.node_name) AS a parent

    Of unpivoted_data c

    LEFT OUTER JOIN unpivoted_data p ON p.employee = c.employee

    AND p.lvl = c.lvl + 1

    GROUP BY c.node_name

    )

    SELECT LPAD (' ' ')

    2 * (LEVEL - 1)

    ) || Node_name AS entity

    OF got_parent

    START WITH parent IS NULL

    Parent = node_name PRIOR CONNECTION

    ;

    In this way, if 'Test' is current 'IT' in one line, but not under what in another line, whether under would consider the 'IT' request and not to be a root.  If 'One Team' sudden 'Testing' in a line, but under "Recruitment" in another line, it will be (arbitrarily) consider it under "recruitment".

  • SQL query for the set of data rows not values

    Hello!

    I use Oracle 10 g (10.2.0.1.0) and I need help to solve this difficult task. I have a huge table with more than 145000 records and I shows you only a sample of it:

    ID TEAMNAME_EN DT TEAMNAME_EN HPROB AM APROB FT
    324813 31/8 / 2012 DEN HAAG GRONINGEN 1.90 3.30 3.10 2
    324823 31/8 / 2012 MAINZ GREUTHER FÜRTH 1.75 3.25 3.65 2
    324805 31/8 / 2012 GAZELEC DIJON 1.60 3.15 4.75 1
    324810 31/8 / 2012 ÖREBRO DJURGÅRDEN 2.80 3.25 2 2.05
    324795 31/8 / 2012 FC KÖLN COTTBUS 1.85 3.20 3.35 2
    324837 31/8 / 2012 PORTLAND WOOD COLORADO RAPIDS 2,00 3.20 2.95 1
    324828 31/8 / 2012 DROGHEDA UNITED, DUNDALK 1.45 3.65 5.25 1
    324827 31/8 / 2012 CORK CITY SHAMROCK ROVERS 3,30 3,80 1.70 2
    324833 31/8 / 2012 BARUERI ASA 2.45 3.20 1-2.30
    324798 31/8 / 2012 GENÇLERBIRLIGI ORDUSPOR'A 2.00 3,10 X 3.00
    324814 31/8 / 2012 ALMERE CITY FC OSS 1,80 3,50 3,20 2
    324830 31/8 / 2012 CRICIÚMA BRAGANTINO 1.25 4.35 1 8.00
    324820 31/8 / 2012 VOLENDAM FC EINDHOVEN 1.80 3.25 3.45 1
    324818 31/8 / 2012 MVV MAASTRICHT TELSTAR 1.40 4.00 X 5.25
    324819 31/8 / 2012 DORDRECHT VEENDAM 1.80 3.25 3.45 1
    324834 31/8 / 2012 CEARÁ GUARATINGUETÁ 1.40 3.85 X 5.50

    If this table consists of
    dates
    teams (hometeam, awayteam)
    numbers for homewin, shoot, awaywin probability
    and the final result as 1, X, 2

    What I want is a sql query that returns to me for each hometeam, awayteam and (if possible in a single line)
    all documents of the hometeam which had the same number of prior probability. For example:
    CEARÁ (last line), I would like to the sql to show me all the records of CEARA who had _1.40 3.85 or 5.50_ in each of the three issues of probability, BUT the problem is that I do want separate lines... I can do so far is to calculate a sum of House probability, probability of drawing, close probability for each team but the same records are calculated again in each game of probability!

    This means if CEARÁ has 1.40-3.85-5.50 in the past it will return me this line only once, and not 3 times (one for each set of probability)

    I hope that I've done my duty,
    Thank you for your time and lights
    N. Saridakis

    Is that what you are looking for:

    select hometeam,
           awayteam,
           hw,
           hd,
           hl
    from  (select hometeam,
                  awayteam,
                  ft,
                  SUM(CASE ft
                      WHEN '1' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hw,
                  SUM(CASE ft
                      WHEN 'X' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hd,
                  SUM(CASE ft
                      WHEN '2' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hl
           from   plays)
    where ft is null
    
  • R12 Payables: SQL query for the list of invoices and their status of Validation

    Hi all

    I am looking for a SQL query that gives me the list of all invoices of AP and their Validation status.

    Thank you
    Anil

    Select invoice_id, invoice_num, invoice_amount, invoice_currency_code, AP_INVOICES_V approval_status_lookup_code;

    Prasanna-

  • SQL query for retrieving data based on Certain model

    Hi all

    I want to retrieve all the identifiers of all the people who are permanently seated during the last hour.

    Data are expressed as below:

    -Creation of the activity Table

    CREATE TABLE activity_log

    (

    Username, NUMBER of

    Activity VARCHAR2 (30),

    StartTime VARCHAR2 (6).

    EndTime VARCHAR2 (6)

    );

    -Filling with sample data

    INSERT INTO activity_log VALUES('39','Walking','09:01','09:05');

    INSERT INTO activity_log VALUES('39','Walking','09:06','09:10');

    INSERT INTO activity_log VALUES('39','Sitting','09:11','09:15');

    INSERT INTO activity_log VALUES('39','Sitting','09:16','09:20');

    INSERT INTO activity_log VALUES('39','Sitting','09:21','09:25');

    INSERT INTO activity_log VALUES('39','Standing','09:26','09:30');

    INSERT INTO activity_log VALUES('39','Standing','09:31','09:35');

    INSERT INTO activity_log VALUES('39','Sitting','09:36','09:40');

    INSERT INTO activity_log VALUES('39','Sitting','09:41','09:45');

    INSERT INTO activity_log VALUES('39','Sitting','09:46','09:50');

    INSERT INTO activity_log VALUES('39','Sitting','09:51','09:55');

    INSERT INTO activity_log VALUES('39','Sitting','09:56','10:00');

    INSERT INTO activity_log VALUES('39','Sitting','10:01','10:05');

    INSERT INTO activity_log VALUES('39','Sitting','10:06','10:10');

    INSERT INTO activity_log VALUES('39','Sitting','10:11','10:15');

    INSERT INTO activity_log VALUES('39','Sitting','10:16','10:20');

    INSERT INTO activity_log VALUES('39','Sitting','10:21','10:25');

    INSERT INTO activity_log VALUES('39','Sitting','10:26','10:30');

    INSERT INTO activity_log VALUES('39','Sitting','10:31','10:35');

    INSERT INTO activity_log VALUES('39','Standing','10:36','10:40');

    INSERT INTO activity_log VALUES('39','Standing','10:41','10:45');

    INSERT INTO activity_log VALUES('39','Walking','10:46','10:50');

    INSERT INTO activity_log VALUES('39','Walking','10:51','10:55');

    INSERT INTO activity_log VALUES('39','Walking','10:56','11:00');

    INSERT INTO activity_log VALUES('40','Walking','09:01','09:05');

    INSERT INTO activity_log VALUES('40','Walking','09:06','09:10');

    INSERT INTO activity_log VALUES('40','Sitting','09:11','09:15');

    INSERT INTO activity_log VALUES('40','Sitting','09:16','09:20');

    INSERT INTO activity_log VALUES('40','Sitting','09:21','09:25');

    INSERT INTO activity_log VALUES('40','Standing','09:26','09:30');

    INSERT INTO activity_log VALUES('40','Standing','09:31','09:35');

    INSERT INTO activity_log VALUES('40','Sitting','09:36','09:40');

    INSERT INTO activity_log VALUES('40','Sitting','09:41','09:45');

    INSERT INTO activity_log VALUES('40','Sitting','09:46','09:50');

    INSERT INTO activity_log VALUES('40','Sitting','09:51','09:55');

    INSERT INTO activity_log VALUES('40','Walking','09:56','10:00');

    INSERT INTO activity_log VALUES('40','Sitting','10:01','10:05');

    INSERT INTO activity_log VALUES('40','Standing','10:06','10:10');

    INSERT INTO activity_log VALUES('40','Standing','10:11','10:15');

    INSERT INTO activity_log VALUES('40','Walking','10:16','10:20');

    INSERT INTO activity_log VALUES('40','Walking','10:21','10:25');

    INSERT INTO activity_log VALUES('40','Walking','10:26','10:30');

    INSERT INTO activity_log VALUES('40','Sitting','10:31','10:35');

    INSERT INTO activity_log VALUES('40','Sitting','10:36','10:40');

    INSERT INTO activity_log VALUES('40','Sitting','10:41','10:45');

    INSERT INTO activity_log VALUES('40','Standing','10:46','10:50');

    INSERT INTO activity_log VALUES('40','Walking','10:51','10:55');

    INSERT INTO activity_log VALUES('40','Walking','10:56','11:00');

    Based on the data, the user ID 39 must be found, since it's been sitting since 09:36-10:35, which is continuous 1 hour.

    Any guidance how to do using SQL query will be of great help and appreciation.

    Thank you very much

    Kind regards

    Bilal

    So what exactly is wrong with the request that I already gave you?

    Just to remind one untested (because of lack of insert statements) rewrite according to your new data:

    with grp as)

    Select

    username

    UserRecognizedActivityID activity

    starttime

    starttime + endetime + 1

    row_number() over (partition by order of starttime userid)

    -ROW_NUMBER() over (partition of userid, UserRecognizedActivityID order of starttime)

    RN

    of activity_log

    )

    Select

    username

    min (starttime) starttime

    max (endtime) endtime

    max (activity) activity

    GRP

    Group userid, rn

    with round (max (endtime) - min (starttime) * 24 * 60) > = 59

  • SQL query for employees, based on a hierarchy of Org

    Hi all

    I need a query for employee information based on the hierarchy of the Org.

    I tried using previous queries in this forum and on the internet, but not closer to.

    Here's the requirement:

    Level1 Level 2 Level 3
    Org Id 81
    102
    103
    104
    111 (parent 104)
    112 (parent 104)
    105

    My requirement is to group employees based on level 2, which should include level 3 employees in the respective level2 parent id.

    Please suggest.

    Query to get hierarchy:
    SELECT
    LPAD(' ',10*(LEVEL-1)) || org.name hierarchy,ose.organization_id_parent,
    org.organization_id
    FROM
    hr_all_organization_units org,
    per_org_structure_elements ose
    WHERE 1=1
    AND org.organization_id = ose.organization_id_child
    AND ose.org_structure_version_id = 61
    --and org.organization_id = 340
    START WITH
    ose.organization_id_parent = 81
    CONNECT BY PRIOR
    ose.organization_id_child = ose.organization_id_parent
    ORDER SIBLINGS BY
    org.location_id,
    ose.organization_id_child 
    
    Required  Columns:
    
    SELECT haou.name, papf.EMPLOYEE_NUMBER, papf.full_name
    FROM 
    per_org_structure_elements ose
    ,hr_all_organization_units haou
    ,per_all_assignments_f paaf
    ,per_all_people_f papf
    WHERE ose.ORGANIZATION_ID_PARENT = 81
    AND ose.ORG_STRUCTURE_VERSION_ID = 61
    AND haou.organization_id = ose.organization_id_child
    --and paaf.organization_id = ose.organization_id_child
    and papf.person_id = paaf.person_id
    and paaf.organization_id = haou.organization_id
    and :P_GIVEN_DATE between papf.effective_start_date and papf.effective_end_date
    and :P_GIVEN_DATE between paaf.effective_start_date and paaf.effective_end_date
    
    
    

    Thank you and best regards,

    Afzal.

    with

    hr_all_organization_units as

    (select 81 organization_id, ' name 81', 'loc_1' any double union location_id

    Select 102, 'name 102', 'loc_1' from dual union all

    Select 103, 'naming 103', 'loc_10' from dual union all.

    Select 104, '104 name', 'loc_5' from dual union all

    105, select 'name 105', 'loc_3' from dual union all

    Select 111, '111 name', 'loc_5' from dual union all

    112, select 'name 112', 'loc_7' from dual

    ),

    per_org_structure_elements as

    (select org_structure_version_id 61, organization_id_parent 81, 102 organization_id_child of all the double union)

    Select 61,81,103 from all the double union

    Select 61,81,104 from all the double union

    Select 61,81,105 from all the double union

    Select 61,104,111 from all the double union

    Select double 61,104,112

    ),

    employees as

    (select 1 emp_id, name 'emp_1', org_id 111 Union double all the)

    Select 2, 'emp_2', 112 double Union all

    Select 3, 'emp_3', 112 double Union all

    Select option 4, 'emp_4', 111 double Union all

    Select 5, 'emp_5', 105 double Union all

    Select 6, 'emp_6', 104 double Union all

    Select 7, "emp_7", 103 double Union all

    Select 8, 'emp_8', 102 double Union all

    Select 9, 'emp_9', 81 of the double

    )

    Select e.name, e.emp_id, o.level_2

    e employees

    left outer join

    (select org.organization_id,regexp_substr(sys_connect_by_path(org.organization_id,'/'). ' / ',' ^ / (\d+)',1,1,'i',1) level_2

    of hr_all_organization_units org,.

    per_org_structure_elements dare

    where ose.org_structure_version_id = 61

    and ose.organization_id_child = org.organization_id

    Start with ose.organization_id_parent = 81

    Connect prior ose.organization_id_child = ose.organization_id_parent

    ) o

    on e.org_id = o.organization_id

    order by emp_id

    EMP_ID NAME LEVEL_2
    1 emp_1 104
    2 emp_2 104
    3 emp_3 104
    4 emp_4 104
    5 emp_5 105
    6 emp_6 104
    7 emp_7 103
    8 emp_8 102
    9 emp_9 -

    Concerning

    Etbin

  • What can be the SQL query for this requirement?

    Hello
    I have a table with the fields like this:

    ID DESC PARENT
    01 02 ABC
    02 01 ABC1
    03 01 ABC2
    04 02 ABC4


    In the table above column PARENT refers to the column ID, but actually in the SQL query, I want to have ID DESC and PARENTDESC (i.e., desc ID value corresponding)

    Output real I need is

    SELECT ID, DESC? from table where ID = someValue. Now, if I provided ID = 01 then output should be like this:

    ID DESC PARDESC
    ABC1 ABC 01


    Can anyone help on what may be the required sql query?

    Published by: bootstrap on April 29, 2011 06:15

    SELECT T1.ID, T1. DESC, T2. / / DESC
    FROM TABLEA T1, T2 TABLEA
    WHERE T1.ID = '01'
    AND T2.ID = T1. PARENT;

  • SQL query for extension able to make NET calls

    Hello

    Is it possible to create a query that can retrieve only the extensions that are able to PSTN calls?

    I am currently interviewing peripheral and numplan for all devices whose device.name is like MS %. However it will only retrieve the IP phones.

    I need to create a query that can recover all other types regardless of what looks like their name of the unit. I intend to run it on 10.5 CUCM and 11.0

    Thank you

    This should help you get the result required that you are looking for.

    http://www.ucguerrilla.com/2012/04/CUCM-SQL-queries-listing-call-forward...

    BR,

    Nadeem

  • SQL Query for Oracle DB followed by using vCOPS

    Hi guys,.

    I installed a general SQL adapter to monitor an Oracle database in my environment. But I am not able to make it work there are a lot of problems in writing a SQL Quries. I work with one of the DBA and we are still not able to write the query to the right. Can someone give me an example of a query so that I can test it or tell me how to write the query to Oracle DB. Examples of files that are given under/samples/folder conf in the plug-in does not help us. So if someone has a link or if someone has it please help me with query files.

    Thanks in advance

    fix. the biggest challenge with the SQL adapter is to write the query in such a way the release of product that is easily consumable by vcops and maps directly to RESOURCEKIND and RESOURCENAME in vcops. The result can also be hierarchical for more efficiency, i.e.

    metric

    -submetric1

    -submetric2

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    ) Select * from given by 2

    Hi Experts,

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

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

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

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

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

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

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

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


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

    15 selected lines.

  • Help with SQL query for SQL experts!

    Hi all

    For the very expert on SQL.

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

    create table t1 (STEP number);

    Insert into t1 select rownum from dba_tables where rownum < 11;

    commit;

    create table t2 (the STEP number, name varchar2 (4), varchar2 (1)) of the State;

    insert into t2 values (1, 'TOTO', ' A');

    insert into t2 values (3, 'TOTO', 'C');

    insert into t2 values (4, 'TOTO', ');

    insert into t2 values (1, 'FIFI', ' A');

    insert into t2 values (6, 'FIFI', 'B');

    commit;

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

    My goal is to list the STATE in the NAME of all the STEPS, even if measures do not exist for a NAME.

    In other words, my query should return a result like this: (query on t1 and t2, of course)

    STEP   1      2             3            4               5            6

    TOTO A C D NO NO NO

    FIFI HAS NO NO NO NO D

    Thank you in advance.

    with the data as)
    Select
    T1. Step step
    name
    State
    Of
    T1, t2
    where
    T1. Step = T2. Step (+)
    )

    Select
    *
    from the data
    Pivot (max (state))
    for step (1,2,3,4,5,6,7,8,9,10)
    )
    where the name is not null

    NAME 1 2 3 4 5 6 7 8 9 10
    TOTO A - C D - - - - - -
    FIFI A - - - - B - - - -

    If the column name must be the stage instead of the name

    with the data as)
    Select
    Step 1 T1. Step
    name as step
    State
    Of
    T1, t2
    where
    T1. Step = T2. Step (+)
    )

    Select
    *
    from the data
    Pivot (max (state))
    for step 1 in (1,2,3,4,5,6,7,8,9,10)
    )
    where the step is not null

  • Access APEX_APPLICATION. G_F01 in a SQL query for a report

    APEX 4.0.2.00.07

    I have a standard report with check boxes. The SQL along the lines of:
    SELECT APEX_ITEM.CHECKBOX(1,empno,'CHECKED') " ",
           ename,
           job
    FROM   emp
    Then I have another report below, I want to drive based on the items checked in the first report. I know that the values of the checkbox in the APEX_APPLICATION. Collection of G_F01. Normally, these are accessible using pl/sql such as:
    FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
        DELETE FROM emp WHERE empno = to_number(APEX_APPLICATION.G_F01(i));
    END LOOP;
    But is it possible that I can access the collection from the sql for my second report.

    that is, I want my sql to be something like:
    SELECT empno, day_of_service
    FROM   emp_timesheet
    WHERE emp_no in <get access to the collection here>
    I was hoping that the collection box would be available in the APEX_COLLECTIONS view, but it doesn't seem to be there.

    Thank you
    John

    John,

    If the goal is to keep the values checked for another treatment then you could add them to a collection yourself.

    create a process on your page that looks like this:
    This will create your collection if not exist or don't delete everything currently in it if it exists and then insert your new selections.

    DECLARE
       l_col_name varchar2(30) := 'EMP_SELECTED';
    BEGIN
        apex_collection.create_or_truncate_collection(l_col_name);
        FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
            apex_collection.add_member(
                l_col_name,
                to_number(APEX_APPLICATION.G_F01(i))
            );
        END LOOP;
    END;
    

    your second question might look like this:

    SELECT empno, day_of_service
      FROM emp_timesheet
     WHERE empno in (select C001 empno
                       from apex_collections ac
                      where ac.collection_name = 'EMP_SELECTED')
    

    Edit
    Some people choose to create a view of some collection queries ontop that will be repeated throughout the application so we can just

    create view selected_emps as
    select C001 empno
      from apex_collections ac
     where ac.collection_name = 'EMP_SELECTED'   
    

    and your new query will look like:

    SELECT empno, day_of_service
      FROM emp_timesheet
     WHERE empno in (select empno
                       from selected_emps)
    

    See you soon,.

    Janet Tyson

    Published by: Tyson Janet on April 6, 2011 10:37

Maybe you are looking for

  • Poor - and not yet no answer customer service!

    Hello! My apologies for the weird subject but heading I really wanted to attract someone's attention because at the present time (a guy called Paul online support side) nobody came back to me at all about my recent visit to your store from Covent Gar

  • 9.3.5 latest ios update now my wifi doesn't connect

    I updated last night, my wifi is connected, and this morning I noticed my wifi connection is not connected, but my other ipad devices and another iphone has no problem with the connection. Anyone here also has problem with wifi aftr update to ios9.3.

  • After update Win OS is not genuine and my product key is not valid

    Hello I have a Toshiba EA60 - 156 computer equium laptop using the preinstalled software. Suddenly after running auto-updates to update, windows think now its not authentic and my product key is not valid. After trying to check online, I was told to

  • DeskJet 1512: scanning problem

    Hi, I have deskjet 1512 all-in-one printer. I have a copy in black and white button as well as a copy in kept button but can not see a scan button as I had on my old previous model?  Is it possible to scan breeds? Thank you

  • Monitor goes blank after windows XP starts.

    After my computer Windows XP starts, the screen turns white.  I can see typical splash screens and the windows icon, that my home screen.  But shortly after so that files are always load, the monitor is going gray.  It is still 'active' designated by