Need help: complex SQL statement

Select segment3, 0 "other income."
, 0 "Sales Services".
, 0 "staff costs".
, 0 "other staff costs".
, 0 'Deputy '.
, 0 'trip '.
, 0 "collaborator".
, 0 'training '.
, 0 'capital '.
, nvl (round (sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0)), 0), 0) "Overhead"
, 0 "financial expenses".
of PAN. SNP_OP_DETAIL@OFA
where segment3 = x.new_cc and period_name = p_period
and segment2 in (select acc_t from the CRP_REPORT_ACCT_DETAIL_T where group_id = 10)
Group of segment3

Please, I do not understand select segment3, 0 'other income'... There is no column called 0, what is the 0s in the select statement?

Secondly, I don't understand PAN. SNP_OP_DETAIL@OFA

Means says:
Select segment3, 0 "other income."
, 0 "Sales Services".
, 0 "staff costs".
, 0 "other staff costs".
, 0 'Deputy '.
, 0 'trip '.
, 0 "collaborator".
, 0 'training '.
, 0 'capital '.
, nvl (round (sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0)), 0), 0) "Overhead"
, 0 "financial expenses".
of PAN. SNP_OP_DETAIL@OFA
where segment3 = x.new_cc and period_name = p_period
and segment2 in (select acc_t from the CRP_REPORT_ACCT_DETAIL_T where group_id = 10)
Group of segment3

Please, I do not understand select segment3, 0 'other income'... There is no column called 0, what is the 0s in the select statement?

0 'other income' means to select a literal value of 0 (zero) with an alias of "other income". double quotes preserve the space and upper/lower case in the alias. This alias (in space) will be difficult to use because of the so called space later.

Secondly, I don't understand PAN. SNP_OP_DETAIL@OFA

PAN is probably a schema, SNP_OP_DETAIL a table or view and @OFA there is a link of database indicating the table in a different database

Tags: Database

Similar Questions

  • Need help with SQL statement

    So I am new to SQL and ORACLE. I need to know how to do the commands below in a single statement. I did it in two here, but I have no idea how do it in one. Any ideas?

    ALTER TABLE books
    ADD Catcode VARCHAR2 (3);

    ALTER TABLE books
    ADD CONSTRAINT books_catcode_fk FOREIGN KEY (catcode)
    REFERENCES (catcode) category;

    Any help appreciated ^^
    SQL> ed
    Wrote file afiedt.buf
    
      1  alter table books
      2    add( catcode varchar2(3),
      3         constraint books_catcode_fk
      4            foreign key( catcode )
      5*        references category( catcode ) )
    SQL> /
    
    Table altered.
    

    Justin

  • Need help with Sql Tunning

    Under Update taking 2 h complete 3000 sets.

    UPDATE ARR_TRANSACTIONS ARR

    SET = NUMBER99

    (SELECT ARR_1.NUMBER99

    OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH

    WHERE ARR_1.ARR_ID = BH. ARR_ID

    AND BH. FLAG = "Y".

    AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID

    AND ARR_1.NUMBER9 IS NOT NULL

    AND ROWNUM = 1)

    WHERE ARR BATCH_ID = 26219

    AND ARR. NUMBER99 IS NULL

    I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.

    Please help with SQL.

    I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.

    In the given situation, I would check:

    • is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
    • Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.

    To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.

    If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.

  • Need help with SQL/PL/SQL for Dates

    Hi Experts - need help with a SQL query.

    I need to insert some date fields in a table called CALENDAR_PERIOD.

    Current data in CALENDAR_PERIOD table with their data types:

    STARTPERIOD (DATE) YEAR (NUMBER) PERIOD_LABEL (Varchar2 255)

    02/11/2014 2014 2014/02/11 SUN

    03/11/2014 2014 14/03/11 MON

    04/11/2014 2014 11/04/14 MAR

    I have to increment above values up to the year 2025. I don't know how to write SQL and increment of these values.

    Ex: My next value should insert: 05/11/2015 2014 11/05/14 WED like that I need to insert data until 12 31, 2025.

    Can you please help me with PL/SQL block?

    Really appreciate your help!

    DB version:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Thank you
    Sandy

    Hello Sandy,

    Maybe something like

    INSERT INTO calendar_period (startperiod, year, period_label)

    SELECT DATE '' 2014-11-04 + LEVEL

    , TO_NUMBER (TO_CHAR (DATE '' 2014-11-04 + LEVEL, "YYYY"))

    , TO_CHAR (DATE '' 2014-11-04 + LEVEL, "MM/DD/YY DY")

    OF the double

    CONNECT BY LEVEL<= date="" '2025-12-314="" -="" date="">

    ;

    ((mais je ne comprends pas pourquoi nous créons une telle table "année" et "period_label" peuvent être calculé à partir de startperiod))

    Best regards

    Bruno Vroman.

  • [help needed] Several insert - SQL statement

    Hello

    This is my table:

    {code}

    create table test

    (

    Identification number,

    DS varchar (6).

    start_date date

    );

    {code}

    There is data in the table.

    {code}

    Insert test values (1, 'DS1982', TO_DATE ('01.03.2014 ',' DD.)) MM YYYY'));

    Insert test values (2, 'DS1982', TO_DATE ('01.04.2014 ',' DD.)) MM YYYY'));

    Insert test values (3, 'DS1982', TO_DATE ('01.05.2014 ',' DD.)) MM YYYY'));

    Insert test values (4, 'DS1982', TO_DATE ('01.06.2014 ',' DD.)) MM YYYY'));

    Insert test values (1, 'DS1999', TO_DATE ('11.04.2014 ',' DD.)) MM YYYY'));

    Insert test values (2, 'DS1999', TO_DATE ('11.05.2014 ',' DD.)) MM YYYY'));

    Insert test values (3, 'DS1999', TO_DATE ('11.06.2014 ',' DD.)) MM YYYY'));

    Insert test values (4, 'DS1999', TO_DATE ('11.07.2014 ',' DD.)) MM YYYY'));

    Insert test values (1, 'DS0009', TO_DATE ('21.01.2014 ',' DD.)) MM YYYY'));

    Insert test values (2, 'DS0009', TO_DATE ('21.02.2014 ',' DD.)) MM YYYY'));

    Insert test values (3, 'DS0009', TO_DATE ('21.03.2014 ',' DD.)) MM YYYY'));

    {code}

    I have to query all records from the table that has:

    Max (start_date) whitin ID and DS culoms.

    So, I have to insert in the record in the table for each DS to condition:

    Each record will be inserted with incremented id whithin DS

    each record inserted must be "newer" than previous 1 month.

    Integration goes up to to_char (sysdate, mm) = to_char (start_date, 'mm').

    Resoult for DS1982 has so (records to insert):

    Insert test values (5, 'DS1982', TO_DATE ('01.07.2014 ',' DD.)) MM YYYY'));

    Insert test values (6, 'DS1982', TO_DATE ('01.08.2014 ',' DD.)) MM YYYY'));

    Insert test values (7, 'DS1982', TO_DATE ('01.09.2014 ',' DD.)) MM YYYY'));

    Insert test values (8, 'DS1982', TO_DATE ('01.10.2014 ',' DD.)) MM YYYY'));

    Insert test values (9, 'DS1982', TO_DATE ('01.11.2014 ',' DD.)) MM YYYY'));

    Insert test values (10, 'DS1982', TO_DATE ('01.12.2014 ',' DD.)) MM YYYY'));

    Insert test values (11, 'DS1982', TO_DATE ('01.01.2015 ',' DD.)) MM YYYY'));

    Insert test values (12, 'DS1982', TO_DATE ('01.02.2015 ',' DD.)) MM YYYY'));

    Insert test values (13, 'DS1982', TO_DATE ('01.03.2015 ',' DD.)) MM YYYY'));

    Insert test values (14, 'DS1982', TO_DATE ('01.04.2015 ',' DD.)) MM YYYY'));

    all together for DS1982

    Insert test values (1, 'DS1982', TO_DATE ('01.03.2014 ',' DD.)) MM YYYY'));

    Insert test values (2, 'DS1982', TO_DATE ('01.04.2014 ',' DD.)) MM YYYY'));

    Insert test values (3, 'DS1982', TO_DATE ('01.05.2014 ',' DD.)) MM YYYY'));

    Insert test values (4, 'DS1982', TO_DATE ('01.06.2014 ',' DD.)) MM YYYY'));

    Insert test values (5, 'DS1982', TO_DATE ('01.07.2014 ',' DD.)) MM YYYY'));

    Insert test values (6, 'DS1982', TO_DATE ('01.08.2014 ',' DD.)) MM YYYY'));

    Insert test values (7, 'DS1982', TO_DATE ('01.09.2014 ',' DD.)) MM YYYY'));

    Insert test values (8, 'DS1982', TO_DATE ('01.10.2014 ',' DD.)) MM YYYY'));

    Insert test values (9, 'DS1982', TO_DATE ('01.11.2014 ',' DD.)) MM YYYY'));

    Insert test values (10, 'DS1982', TO_DATE ('01.12.2014 ',' DD.)) MM YYYY'));

    Insert test values (11, 'DS1982', TO_DATE ('01.01.2015 ',' DD.)) MM YYYY'));

    Insert test values (12, 'DS1982', TO_DATE ('01.02.2015 ',' DD.)) MM YYYY'));

    Insert test values (13, 'DS1982', TO_DATE ('01.03.2015 ',' DD.)) MM YYYY'));

    Insert test values (14, 'DS1982', TO_DATE ('01.04.2015 ',' DD.)) MM YYYY'));

    I hope someone can help me with this problem!

    Thank you!

    This...

    SELECT the id + id LEVEL,

    DS,

    Start_date ADD_MONTHS (start_date, Level)

    Of

    (SELECT ds,

    Max (ID) id,

    Date_début Max (start_date)

    OF the test

    GROUP BY ds)

    CONNECT BY LEVEL<=>

    AND PREREQUISITES ds = ds

    AND PRIOR DBMS_RANDOM. VALUE IS NOT NULL.

    Thank you

    Ann

  • Help needed on complex sql resolution

    Hi all

    I have a table such as indicated and wanted to insert these records in both tables and get the number of each type...
    CREATE TABLE RETURN_DEV
    (
      RCODE       VARCHAR2(4 BYTE),
      RNUMBER     VARCHAR2(16 BYTE),
      RDESC       VARCHAR2(40 BYTE),
      RDATE_TIME  VARCHAR2(16 BYTE),
      RQUANTITY   VARCHAR2(20 BYTE)
    )
    
    
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0987', '919341035404586', 'POS:00003:RETR', '20100112112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0910', '929341035404586', 'POS:00003:REMR', '20100102112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0914', '939341035404586', 'POS:00003:REMR', '20100111112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0997', '357991027440360', 'POS:00003: WEXC', '20100102112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0997', '347991027440360', 'POS:00003: WEXC', '20100102112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0987', '949341035404586', 'POS:00003:SAXP', '20100512112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0956', '949341035404586', 'POS:00003:RETR', '20100212112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0968', '949341035404586', 'POS:00003:SAXP', '20100312112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0967', '997991027440360', 'POS:00003: USXP', '20060102112324', '-1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0967', '997991027440360', 'POS:00003: USXP', '20070102112324', '1');
    Insert into RETURN_DEV    (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY)
     Values    ('0967', '997991027440360', 'POS:00003: USXP', '20080102112324', '-1');
    COMMIT;
    
    Now my Algorithm go like this 
    
    step 1: Load 'RET' type into Retail_Table and Count 'RET' type
    If the RCODE  is not in [0910, 0914, 0997] and the RDESC begins with "POS:00003" and RQUANTITY =+1 load these as 'RET' type
    
    Step2: Load   'REM' type type into Retail_Table and Count 'REM' type
    If the RCODE  is in [0910, 0914] and RQUANTITY = +1, load these as 'REM' type
    
    Step3: Load  'WEX' type into Retail_Table and Count 'WEX' type
    
    If the RCODE  = 0997 and RQUANTITY = +1, load these as 'WEX' type
    
    For me main problem starts here....
    
    Step4: Load'RET' INTO  type  and 'RETXP' into retail_exceptions, and update the count of 'RET' Type and count 'RETXP' type
    
    If the RCODE  is not in [0910, 0914, 0997] and the RDESC  begins with "POS:00003" 
    and  if there is more than one record fitting that criteria in the file for the RNUMBER and the newest record chronologically (RDATE_TIME) has RQUANTITY = +1, 
    then load the latest record as Retail Returns and load all other records into retail_exceptions table.
    
    Step5: Load Retail Returns Exceptions as 'RETXP', update the count of Retail Returns  and add the count of exceptions
    
    If the RCODE  is not in [0910, 0914, 0997] and the RDESC  begins with "POS:00003" 
    and if there is more than one record fitting that criteria  for this RNUMBER and the newest record chronologically (RDATE_TIME)  has RQUANTITY = -1, 
    then load all records into to the Retail exceptions table
    I asssume we can get the account once the algorithm sucssefully inserts the date in the tables.
    Both the table has the same structure as shown..
    
    CREATE TABLE Retail_Table
    (
      RCODE       VARCHAR2(4 BYTE),
      RNUMBER     VARCHAR2(16 BYTE),
      RDESC       VARCHAR2(40 BYTE),
      RDATE_TIME  VARCHAR2(16 BYTE),
      RTYPE   VARCHAR2(20 BYTE)
    )
    
    
    CREATE TABLE Retail_Table_Exceptions
    (
      RCODE       VARCHAR2(4 BYTE),
      RNUMBER     VARCHAR2(16 BYTE),
      RDESC       VARCHAR2(40 BYTE),
      RDATE_TIME  VARCHAR2(16 BYTE),
      RTYPE   VARCHAR2(20 BYTE)
    )
    Thanks in advance...

    Published by: Rede on October 19, 2010 16:20

    Hello

    Sorry, I don't understand still.

    Rede says:
    Thanks Frank.I thought to explain clearly, but it became huge, then I'll be more clear and precise...

    I expect the output as shown below

    Output Sample data of Retail Table....
    
    RDESC            RQUANTITY     RNUMBER     TRANSACTION_TYPE
    
    POS:00003: USXP     -1     997991027440360     RET
    POS:00003: WEXC     1     347991027440360     WEX
    POS:00003: WEXC     1     357991027440360     WEX
    POS:00003:REMR     1     929341035404586     REM
    POS:00003:REMR     1     939341035404586     REM
    
    out put sample data of Retail_Exception Table
    
    RDESC            RQUANTITY     RNUMBER     TRANSACTION_TYPE
    POS:00003: USXP     -1     997991027440360     RETXP
    POS:00003: USXP     1     997991027440360     RETXP
    POS:00003:RETR     1     949341035404586     RETXP
    POS:00003:SAXP     1     949341035404586     RETXP
    

    CREATE orders TABLE for the retail and retail_exception do not have a rquantity column. If they have this column?
    Are the other columns (rcode and rdate_time) of retail and retail_exception supposed to be NULL at this point?

    What does each line in these tables?
    Why there are 9 rows in both tables combined, instead of 11?

    What i want is individaul counts of all trasaction types.If we can get the counts at time of DML querry it will be good.
    But i want to keep them in a local variable thats the reason i want to do it in a seperate sql querry.
    
    as shown below  
    
    Transaction_Type    Count
    RETXP                    4
    WEX                      2
    RET                       2
    

    Please explain how you get these results.
    Why is the number 2 when transaction_type = "RET"? Why not 1?
    Why don't you want a line to transaction_type = "REM"?

    These are all numeric values only. since i am getting these values from a external table i kept them as Varchar's.
    But i will change them accordingly.
    
    What i am trying to do is i grouping the items on the different conditions given below
    
    1. When RCODE In ('0997')            And Rquantity = '1'   Then 'WEX'
    
    2. When RCODE In ('0910', '0914') And Rquantity = '1'    Then 'REM'
    
    3. When RCODE Not  In ('0997', '0910', '0914')   And RDesc Like 'POS:00003%'
    And Count ( * ) Over (Partition By RNUMBER) = 1 Then  'RET'
    
    its easy till above...but if the third condition has more than 1 record and if the top most record has 
    
    4.    Rquantity = '-1' then categorise all the records  'RETXP' of that type   ( that satisfies the third condition)   else if top most record
    5.    Rquantity = '1' then first record should be categorised as 'RET' and the remaining of that type as 'RETXP'.
    
    top most is the record that is sorted by date for a given  RNumber.
    

    What is the "first record"? Is it the same as the 'highest '?

    Please give specific examples of how you get the desired results of the sample data that you posted.

    For example, how do you get the output line:

    RDESC               RQUANTITY  RNUMBER           TRANSACTION_TYPE
    ---------------   ---------  ---------------  ----------------
    POS:00003: USXP       -1          997991027440360  RET
    

    This line of output appears to be the 'top most' line for rnumber = '997991027440360':

    RCODE RNUMBER          RDESC              RDATE_TIME       RQUANTITY
    ----- ---------------- ------------------ ---------------- ---------
    0967  997991027440360  POS:00003: USXP    20060102112324   -1
    0967  997991027440360  POS:00003: USXP    20070102112324   1
    0967  997991027440360  POS:00003: USXP    20080102112324   -1
    

    Rule 4 does not apply to this rnumber? Isn't the line with rdate_time = '20060102112324' the line ' top more? It is not rquantity = '-1'?

    You can do the simple CASE expression (and probably faster) some of the functions of calculation only once, in a subquery, like this:

    WITH     got_analytics     AS
    (
         SELECT     rd.*
         ,     COUNT (*)           OVER ( PARTITION BY  rnumber)     AS rnumber_cnt
         ,     FIRST_VALUE (rquantity) OVER ( PARTITION BY  rnumber
                                    ORDER BY          rdate_time
                                  )                    AS top_rquantity
         ,     ROW_NUMBER ()          OVER ( PARTITION BY  rnumber
                                    ORDER BY          rdate_time
                                  )                    AS seq_number
         FROM     return_dev     rd
    )
    SELECT     rdesc
    ,      rquantity
    ,      rnumber
    ,     CASE
                WHEN  rcode      IN ('0997')
                AND   rquantity      = '1'               THEN     'WEX'
                WHEN  rcode           IN ('0910', '0914')
                AND   rquantity      = '1'                THEN     'REM'
                WHEN  rcode          IN ('0997', '0910', '0914')
                AND   rdesc      NOT LIKE 'POS:00003%'     THEN     NULL
                WHEN  rnumber_cnt     = 1               THEN     'RET'
             WHEN  top_rquantity     = '-1'               THEN     'RETXP'
             WHEN  top_rquantity     != '1'               THEN     NULL
             WHEN  seq_number     = 1               THEN     'RET'
                                       ELSE     'RETXP'
         END     AS transaction_type
    FROM     got_analytics
    ;
    

    I know that's not what you want, but I think that it is a step in the right direction.

  • Need help with sql query performance

    Dear all,

    I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.

    Select rownum LINE_NUM,

    A.LINE_ID,

    TO_CHAR (A.INVITMID),

    TO_NUMBER (A.PICKQTY),

    UNLOADINGPNT NULL,

    RRNUM NULL,

    WORKORDNUM NULL,

    WORKORDDESC NULL,

    A.PONUM,

    DTR_DUMB NULL,

    A.DESCRIPTION,

    FROM_SUB NULL,

    TO_SUB NULL,

    NO SOURCE,

    ASSET_NUMBER NULL,

    A.RECEIPTNUM,

    MOVEORD NULL,

    FROM_LOC NULL,

    TO_LOC NULL,

    MSD_NUM NULL,

    CONTAIN_LINE NULL,

    A.UOM,

    A.PO_RELEASE

    de)

    Select headerid Po.Po_Header_Id,

    rcv1. Po_Line_Id LINE_ID,

    rcv1.item_id INVITMID,

    (NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,

    Po.Segment1 PONUM,

    Rcv1.Receipt_Num RECEIPTNUM,

    Rcv1.Item_Desc DESCRIPTION,

    Rcv1.Transact_Uom GLU,

    Rcv1.Po_release

    Po_Headers_All in.,.

    (Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "EXPENSES".

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    UNION ALL

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND B.ITEM_ID IS NULL

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "WORKSHOP".

    D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3

    GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),

    (SELECT A.PO_LINE_ID,

    Sum (A.Quantity) transact_qty,

    A.PO_HEADER_ID,

    C.RECEIPT_NUM

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2

    Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)

    And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)

    And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)

    And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)

    Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has

    Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Please find the attached PLAN to EXPLAIN.

    EXPLAINPLAN.jpg

    Thank you

    May be essentially the same join (between a, b, c and d) twice instead of three times

    sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2

    We can work on what we can see only

    Select rownum line_num,

    rcv1.po_line_id line_id,

    TO_CHAR (rcv1.item_id) invitmid,

    NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,

    unloadingpnt null,

    rrnum null,

    workordnum null,

    workorddesc null,

    Po. Ponum Segment1,

    dtr_dumb null,

    description of the rcv1.item_desc,

    from_sub null,

    to_sub null,

    No source,

    asset_number null,

    rcv1.receipt_num receiptnum,

    moveord null,

    from_loc null,

    to_loc null,

    msd_num null,

    contain_line null,

    Glu rcv1.transact_uom,

    rcv1.po_release

    of po_headers_all in.

    left outer join

    (select a.po_header_id,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description item_desc,

    a.unit_of_measure transact_uom,

    Sum (a.Quantity) transact_qty,

    d.release_num po_release

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    po_line_id,

    destination_type_code,

    unit_of_measure,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "to DELIVER".

    and upper (a.destination_type_code) ('charge', 'WORKSHOP')

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    where upper (a.destination_type_code) = "EXPENSES".

    or (upper (a.destination_type_code) = 'WORKSHOP'

    and b.item_id is null

    )

    A.po_header_id group,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description,

    a.unit_of_measure,

    d.release_num

    ) rcv1

    On po.po_header_id = rcv1.po_header_id

    left outer join

    (select a.po_line_id,

    Sum (a.Quantity) transact_qty,

    a.po_header_id,

    c.receipt_num

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    A.po_line_id group,

    a.po_header_id,

    c.receipt_num

    ) rcv2

    On rcv1.po_line_id = rcv2.po_line_id

    and rcv1.receipt_num = rcv2.receipt_num

    where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)

    Concerning

    Etbin

  • Run multiple chooses due to several input values (need help in SQL)

    Hello

    I would need to run multiple SQL select statements I get input of several results of the subquery. In my test case, I get three 3 results of the subquery

    Select ALL_TABLES where LAST_ANALYZED is not null AND OWNER of TABLE_NAME = "IHS" AND TABLE_NAME LIKE '_TBL_PROCESS %' AND (SYSDATE-LAST_ANALYZED) < 1 order by (SYSDATE-LAST_ANALYZED
    The complete query is:

    SELECT SDE_ID, SERVER_ID, REGISTRATION_ID, TABLE_NAME, CONNECTOR, START_TIME, NODENAME OF THE

    * (select ALL_TABLES where LAST_ANALYZED is not null AND OWNER of TABLE_NAME = 'IHS' AND TABLE_NAME LIKE '_TBL_PROCESS %' AND (SYSDATE-LAST_ANALYZED) < 1 order by (SYSDATE-LAST_ANALYZED)) *.

    Can someone help me to get the appropriate SQL code?

    Thank you
    Dejan

    Right. I should have put a comment explaining that. I used the name A_TBL_PROCESS because the WHERE clause has
    'AND table_name like '% _TBL_PROCESS' ' then yes that should be a table name that will be selected.

  • Need help with SQL Loader

    I have a third-party site that transforms the information into a csv summary. I can't change the format, and they are not ready to give directly from db and db, so I try and then import it. I'm trying to use SQL Loader, but I can't seem to make it work. I looked in the documentation (VERY rare examples) as well as several websites and I can't find anything that can help out me.

    Control file:
    LOAD DATA
    INFILE 'Daily_Diagnostics_test.csv'
    BADFILE 'Diag_failed.csv'
    APPEND
    INTO TABLE ROAD_DIAGS
    FIELDS TERMINATED BY ","
    --WHEN VEHICLE != 'Vehicle' AND VEHICLE != 'Total'
    (VEHICLE, DRIVER, START_DATE, START_TIME, START_TZ, END_DATE, END_TIME, END_TZ, 
     TM_DRV_MINS, TM_IDLE_MINS, TM_PTO_MINS, TRIP_TM_MINS,
     FUEL_DRV_GALS, FUEL_IDLE_GALS, FUEL_PTO_GALS, FUEL_TRIP_GALS, FUEL_START_GALS,
     MPG, DRV_MPG, START_ODOM, END_ODOM, DIFF_ODOM, AVG_MPH, MAX_MPH, MAX_RPM,
     DATE1, TM1, TZ1, ADDRESS_NUM1, ADDRESS_STREET1, ADDRESS_ST1, ADDRESS_ZIP1, ADDRESS_COUNTY1,
     DATE2, TM2, TZ2, ADDRESS_NUM2, ADDRESS_STREET2, ADDRESS_ST2, ADDRESS_ZIP2, ADDRESS_COUNTY2,
     STOP_CT, FAULT_CODE, HARD_BRAKE)
    Note that the line WHEN is commented out, because I can't make it work.

    and here is a sample of the data:
    Vehicle,Driver,Start Date,Start Time,Timezone,End Date,End Time,Timezone,Driving (hh:mm),Idle (hh:mm),PTO (hh:mm),Trip (hh:mm),Driving (gals),Idle (gals),PTO (gals),Trip (gals),Before Trip (gals), MPG,Driving MPG,Start,End,Trip Distance (miles),Average(MPH),Maximum(MPH),Maximum RPM(rpm),Date,Time,Timezone,Address,Street,City,State,Zip,County,Date,Time,Timezone,Address,Street,City,State,Zip,County,Stop Count,Fault Code,Hard Brake,
    26033, ,01/23/08,12:40 AM,MST,01/23/08,12:42 AM,MST,0,3,0,3,0,0.12,0,0.12, ,0,0,295829.22,295829.22,0,0,6.84, ,01/23/08,12:23 AM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,12:23 AM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,0,4, ,
    26033, ,01/23/08,12:43 AM,MST,01/23/08,04:03 AM,MST,126,74,0,200,0,0,0,0, ,0,0,295829.22,295914.97,85.75,25.72,67.11, ,01/23/08,12:23 AM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,03:56 AM,MST,0,COUNTY ROAD 125,SIDNEY,MT,59270,RICHLAND,8,3, ,
    26033, ,01/23/08,04:03 AM,MST,01/23/08,12:29 PM,MST,317,190,0,507,0,0,0,0, ,0,0,295914.97,296139.9,224.94,26.64,65.87, ,01/23/08,03:56 AM,MST,0,COUNTY ROAD 125,SIDNEY,MT,59270,RICHLAND,01/23/08,12:29 PM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,14,5, ,
    Total, , , ,443,267,0,710,0,0.12,0,0.12, ,0,0,295829.22,296139.91,310.69,26.38,67.11, , , , , , , , , , , , , , , , , , , ,22,12,0,
    Vehicle,Driver,Start Date,Start Time,Timezone,End Date,End Time,Timezone,Driving (hh:mm),Idle (hh:mm),PTO (hh:mm),Trip (hh:mm),Driving (gals),Idle (gals),PTO (gals),Trip (gals),Before Trip (gals), MPG,Driving MPG,Start,End,Trip Distance (miles),Average(MPH),Maximum(MPH),Maximum RPM(rpm),Date,Time,Timezone,Address,Street,City,State,Zip,County,Date,Time,Timezone,Address,Street,City,State,Zip,County,Stop Count,Fault Code,Hard Brake,
    26035, ,01/23/08,03:59 AM,MST,01/23/08,09:05 AM,MST,222,85,0,306,50.87,1.5,0,52.37, ,3.32,3.42,285056.53,285230.5,173.98,34.07,68.97, ,01/23/08,03:24 AM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,01/23/08,09:00 AM,MST,0,COUNTY ROAD 338,SAVAGE,MT,59262,RICHLAND,7,3, ,
    26035, ,01/23/08,09:06 AM,MST,01/23/08,03:37 PM,MST,273,118,0,391,68.5,1.5,0,70, ,3.24,3.31,285230.5,285457.3,226.8,34.8,69.59, ,01/23/08,09:00 AM,MST,0,COUNTY ROAD 338,SAVAGE,MT,59262,RICHLAND,01/23/08,03:37 PM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,11,3, ,
    26035, ,01/23/08,03:45 PM,MST,01/23/08,04:38 PM,MST,32,21,0,53,7.37,0.25,0,7.62, ,3.42,3.54,285457.3,285483.4,26.1,29.73,67.73, ,01/23/08,03:37 PM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,01/23/08,04:33 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,2,3, ,
    26035, ,01/23/08,04:49 PM,MST,01/23/08,10:22 PM,MST,256,76,0,332,52,1.25,0,53.25, ,3.71,3.8,285483.4,285681.0,197.6,35.67,64, ,01/23/08,04:33 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,10:17 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,9,3, ,
    26035, ,01/23/08,10:25 PM,MST,01/23/08,10:35 PM,MST,4,5,0,10,0.37,0,0,0.37, ,1.68,1.68,285681.0,285681.62,0.62,3.9,24.85, ,01/23/08,10:17 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,10:35 PM,MST,0,COUNTY ROAD 338,SAVAGE,MT,59262,RICHLAND,1,5, ,
    Total, , , ,787,305,0,1092,179.11,4.5,0,183.61, ,3.4,3.49,285056.53,285681.62,625.1,34.35,69.59, , , , , , , , , , , , , , , , , , , ,30,17,0,
    As you can see, I need to have the SQL Loader to ignore the header and summary lines that appear for each grouping. Your suggestions are welcome as I need to implement this in an automatic process, I can call with a batch script.

    blarman74 wrote:
    Can anyone suggest how to fix this problem? The log file shows this error:

    Record 8: Rejected - Error on table ROAD_DIAGS, column DATE2.
    ORA-01858: a non-numeric character was found where a numeric was expected
    

    The error message is clear - you try to load a value "non-date" in a DATE column and, therefore, sql * loader berms.
    That points to a discrepancy between the list of columns in the control file and, in the data file.
    Note the position of the table of the "DATE2" column in the table "ROAD_DIAGS":

    test@XE>
    test@XE> l
      1  select table_name,
      2         column_name,
      3         column_id
      4    from user_tab_columns
      5   where table_name='ROAD_DIAGS'
      6*    and column_name='DATE2'
    test@XE> /
    
    TABLE_NAME      COLUMN_NAME      COLUMN_ID
    --------------- --------------- ----------
    ROAD_DIAGS      DATE2                   34
    
    test@XE>
    

    If your control file specifies that the 34th column in the data file must be "DATE2". However-

    test@XE>
    test@XE> -- display the line number and the 34th column of the data file
    test@XE>
    test@XE> !perl -ne '{@a=split/,/; print $.,"\t",$a[33],"\n"}' Daily_Diagnostics_test.csv
    1       County
    2       RICHLAND
    3       RICHLAND
    4       RICHLAND
    5
    6       County
    7       RICHLAND
    8       RICHLAND
    9       RICHLAND
    10      RICHLAND
    11      RICHLAND
    12
    
    test@XE>
    

    the 34th column in your data file is 'COUNTY', which is counted in your control file.

    Here is the list of the columns for 29 to 37 positions in the csv file:

    test@XE>
    test@XE> !perl -ne '{if ($. == 1) {@a=split/,/; foreach $i (28..36) {print $i+1,"\t",$a[$i],"\n"}}}' Daily_Diagnostics_test.csv
    29      Address
    30      Street
    31      City
    32      State
    33      Zip
    34      County
    35      Date
    36      Time
    37      Timezone
    
    test@XE>
    test@XE>
    

    And here are the columns specified in the control file:

      ...
      ...
      ADDRESS_NUM1,
      ADDRESS_STREET1,
      ADDRESS_ST1,
      ADDRESS_ZIP1,
      ADDRESS_COUNTY1,
      DATE2            DATE "MM/DD/YYYY",
      TM2              DATE "HH:MI AM",
      TZ2,
      ...
      ...
    

    (You can open the csv file in MS Excel to get a better picture of the data in there).

    As seen above, due to the incompatibility, sql * loader loads 'City' in ADDRESS_ST1, 'State' in ADDRESS_ZIP1, "Zip" in ADDRESS_COUNTY1 and DATE2 "County" - where it error.

    The solution would be-

    (a) If you want to load the 'City' information from the data file, and then add the "City" column in the table (if nonexistent) and specify in the control file.

    (b) If you do not want to load the 'City' information from the data file, you can specify a column to 'FILL' in the file of control as follows:

      ...
      ...
      ADDRESS_NUM1,
      ADDRESS_STREET1,
      city1            FILLER,
      ADDRESS_ST1,
      ADDRESS_ZIP1,
      ADDRESS_COUNTY1,
      DATE2            DATE "MM/DD/YYYY",
      TM2              DATE "HH:MI AM",
      TZ2,
      ADDRESS_NUM2,
      ADDRESS_STREET2,
      city2            FILLER,
      ADDRESS_ST2,
      ADDRESS_ZIP2,
      ADDRESS_COUNTY2,
      ...
      ...
    

    Hope that helps,
    isotope

  • need help with SQL Server 2008 R2 deadlock uninstall process

    I installed SQL Server 2008 R2 trial version on my PC running Windows Vista Ultimate, a day ago, but he placed himself completely in the disk partition (E :) that I specified. [i.e. I found some parts of the installation in my C:\program files as well as a USB as well].

    I tried to uninstall SQL Server 2008 R2, but was only partially successful.  I'm prevented from uninsalling the main parts using the programs and features Panel - that is "Microsoft SQL Server 2008 R2" and "Microsoft SQL Server 2008 R2 Setup (in English).

    Still visible are:

    1 C:\Program Files (x 86) \Microsoft SQL Server

    2 C:\Program Files (x 86) \Microsoft Visual Studio 9.0

    3 C:\ProgramData\Microsoft\Windows\Start demarrer\programmes\microsoft SQL Server 2008 R2

    I would like your help to uninstall the other goals of SQL Server, so that I can do a clean install once more.

    Any advice on how SQL Server 2008 R2 evaluation version must be correctly installed what a future unistall is not messy, would be welcome.

    Hello

    Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the SQL Server forums. Please post your question in the SQL Server forums.

    http://social.msdn.Microsoft.com/forums/en/category/SQLServer

  • Need help with sql query

    Dear all,

    I have a sql like query below

    SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER

    MTL_TXN_REQUEST_HEADERS D,.

    MTL_TXN_REQUEST_LINES, E.

    MTL_MATERIAL_TRANSACTIONS G,.

    Mtl_Transaction_Types I have

    WHERE D.HEADER_ID = E.HEADER_ID

    AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID

    AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')

    AND E.LINE_ID = G.MOVE_ORDER_LINE_ID

    AND D.MOVE_ORDER_TYPE = 5

    TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')

    D.REQUEST_NUMBER GROUP

    I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.

    above query is back under results

    results.jpg

    If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.

    so in the example above, it must return

    FIRST REQUEST NUMBER LAST NUMBER

    2383                                      1886

    Thank you

    select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min
         , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max
      from (
            select min(g.transaction_date) transaction_date
                 , d.request_number
              from mtl_txn_request_headers d
                 , mtl_txn_request_lines e
                 , mtl_material_transactions g
                 , mtl_transaction_types i
             where d.header_id                    = e.header_id
               and g.transaction_type_id          = i.transaction_type_id
               and upper(i.transaction_type_name) = upper('WIP Issue')
               and e.line_id                      = g.move_order_line_id
               and d.move_order_type              = 5
               and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014')
             group
                by d.request_number
           )
    
  • need help with sql queries

    Dear all,

    I have a parameter like below

    11000048,11000050

    I need to convert in SQL format below, please help me

    "11000048","11000050"


    ' parameter would be so separated by commas, I need to convert in above format, if the parameter is a number say 1111111 must convert it as "1111111" in sql.


    Please help me.


    Thank you

    You can do it

    your_parameter: = "" ' | " Replace (your_parameter, ",", "",""). '"';

  • Need help on SQL


    Please help me on the following sql.

    TABLE 1:

    IS_OUTL_IDHRS_TYP_CDEFFECTIVE_DATE
    IS04408ATM5 JUNE 13
    IS04408CUSTDSPOCTOBER 5, 13
    IS04408DRVTLRNOVEMBER 5, 13

    TABLE 2:  This table will have future effective dates for a particular record. We have to search on the second table and take the entry into force and mark as previous record end date.

    IS_OUTL_IDHRS_TYP_CDEFFECTIVE_DATE
    IS04408CUSTDSPNOVEMBER 5, 13
    IS04408CUSTDSP2 JANUARY 14

    RESULT:

    IS_OUTL_IDHRS_TYP_CDEFFECTIVE_DATEEND_DATE
    IS04408ATM5 JUNE 13
    IS04408DRVTLRNOVEMBER 5, 13
    IS04408CUSTDSPOCTOBER 5, 13NOVEMBER 4, 13
    IS04408CUSTDSPNOVEMBER 5, 131 JANUARY 14
    IS04408CUSTDSP2 JANUARY 14

    Hello

    Therefore, each line of output, that you want to include end_date, based on a value between similar line, when there is one.

    This looks like a job for the analytical function of LEAD, something like this:

    WITH union_data AS

    (

    SELECT is_outl_id, hrs_typ_cd, effective_date

    FROM table_1

    UNION ALL

    SELECT is_outl_id, hrs_typ_cd, effective_date

    FROM table_2

    )

    SELECT is_outl_id, hrs_typ_cd, effective_date

    Advance (effecive_date) OVER (PARTITION BY hrs_typ_cd

    , is_outl_id - can - be

    ORDER BY effective_date

    ) - 1 AS end_date

    Of union_data

    ORDER BY is_outl_id - can - be

    hrs_typ_cd

    effective_date

    ;

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Report when the above query is to give erroneous results and explain, using specific examples, how to get the correct results of data provided in these places.  If you have changed the query at all, your postal code.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Need help with SQL Query - change of name history of audit table.

    I need your help to find the result in the following way...


    Emp No    New_name    Old_Name
    -----------------------------------------------
    1           Name3        Name2
    1           Name2        Name1
    create table emp(emp_id number(10),
    emp_name varchar(50),
    constraints emp_pk primary key(emp_id) );
    
    
    
    create table emp_audit(
    audit_id number(10),
    emp_id number(10),
    emp_name varchar(50),
    audit_date date,
    constraints emp_audit_pk primary key (audit_id),
    constraints  emp_audit_emp_fk foreign key(emp_id)  references emp(emp_id));
    
    insert into emp values(1,'Name3');
    
    
    insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date)
    values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy'));
    insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date)
    values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy'));
    commit;
    Thank you...

    Dipabkar Bédard (DB) wrote:

    We write is the query without using "partition by" in oracle...?

    with t as (
               select  audit_id,
                       emp_id,
                       emp_name,
                       row_number() over(order by audit_id) rn
                 from  emp_audit
                 order by emp_id,
                          audit_id
              )
    select  a.audit_id,
            a.emp_id,
            a.emp_name old_name,
            nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name
      from  t a left join t b
            on (
                    b.emp_id = a.emp_id
                and
                    b.rn = a.rn + 1
               )
    /
    
      AUDIT_ID     EMP_ID OLD_NAME                                           NEW_NAME
    ---------- ---------- -------------------------------------------------- ------------
             1          1 Name1                                              Name2
             2          1 Name2                                              Name3
    
    SQL> 
    

    And without analytical functions:

    with t1 as (
                select  audit_id,
                        emp_id,
                        emp_name
                  from  emp_audit
                  order by emp_id,
                           audit_id
               ),
         t2 as (
                select  audit_id,
                        emp_id,
                        emp_name,
                        rownum rn
                  from  t1
               )
    select  a.audit_id,
            a.emp_id,
            a.emp_name old_name,
            nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name
      from  t2 a left join t2 b
            on (
                    b.emp_id = a.emp_id
                and
                    b.rn = a.rn + 1
               )
    /
    
      AUDIT_ID     EMP_ID OLD_NAME                                           NEW_NAME
    ---------- ---------- -------------------------------------------------- ----------
             1          1 Name1                                              Name2
             2          1 Name2                                              Name3
    
    SQL> 
    

    SY.

  • need help on sql on the full month

    Hello

    I have a table as below:

    The table name:

    Information
    -----------------
    staff_number
    Date
    clock_in
    clock_out
    Note

    I want to create sql which will list down all date selection staffnumber

    Select date, clock_in, staff_number, clock_out, information note where (date > = to_date('01/01/2010') and date < = to_date('01/02/2010')) and staff_number = "012345 '



    Can someone help me on how to change the sql code out in the list, if there is no database on a certain date.

    For example
    012345 8.10 01/01/2010 17:30
    012345 8.12 02/01/2010 16:30
    012345 03/01/2010 - not in the database, but I want it appears in sql
    012345 04/01/2010 08:30 18:40
    012345 8.10 05/01/2010 16:30
    012345 06/01/2010 08:30 16:30
    ....
    012345 8.10 02/01/2010 16:30


    Thanks in advance

    You don't need LAST_DAY then:

    select to_date('13/01/2010', 'dd/mm/rrrr')+ level-1 dt
    from dual
    connect by level <= to_date('23/02/2010', 'dd/mm/rrrr')-to_date('13/01/2010', 'dd/mm/rrrr')+1;
    

    (And subtract from the most recent date)

Maybe you are looking for