In single SQL query?

Hi...
I need to write one single sql to get execution audit and map stating with all error details using all possible owb audit tables..
Am new to the technology..fresher..could any one help me out regarding this query.
Regards,
Gautham

Check this
find mapping of particular pf?

Similar Messages

  • Update two different tables by a single sql query:

    Hi All,
    i need to update two different talbes in a single sql query..
    i m using the following query
    UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
    AND
    UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    i m getting the following error:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
    SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    but when i m ushin the same query in Microsoft SQL Server it executes properly:
    please help me out...

    Duplicate thread. I've already answered on your other thread...
    update two different tables by a single sql query:

  • Single SQl Query with different where conditions

    Experts,
    I have a requirement to design a report. Here are the details
    I have Report table layout
    Profit center Gross sales (This Year) Gross Sales (Last Year) % change Year of Year
    The Report has a selection of entering the Start Date.
    I have a single table in oracle which has profit center and Gross Sales Values on daily basis.
    I want to write a single sql query to calculate both Gross Sales current year and Gross Sales Last Year. I can calculate Gross Sales Current Year by putting the where condition for start date = Current Year Date which i pass through report. I want to calculate the Gross Sales Last Year in the Same query by putting the different where condition i.e start date = Last Year date based on the date input.
    I dont know how to put two where conditions in single query for two different columns.
    Any help will be appreciated.
    Thanks in advance
    Regards
    Santosh

    instead of changing your where clause couldn't you just determine the yearly totals from your table and then use the lag statement to get last years total?
    something like this?
    I just made up 10,000 days worth of sales and called it fake table it is supposed to represent a variant of the table you were describing as your base table.
    with fake_table as
    ( select trunc(sysdate + level) the_day,
    level daily_gross_sales
    from dual
    connect by level < 10001
    select yr, year_gross_sale, lag(year_gross_sale) over (order by yr) prev_year_gross_sale,
    (year_gross_sale - lag(year_gross_sale) over (order by yr))/year_gross_sale * 100 percent_change
    from
    (select distinct yr, year_gross_sale from
    select the_day,
    daily_gross_sales,
    extract(year from the_day) yr,
    extract(year from add_months(the_day,12)) next_yr,
    sum(daily_gross_sales) over (partition by extract(year from the_day)) year_gross_sale
    from fake_table
    order by yr
    )

  • Single SQL query

    can a single SQL query insert data into 2 different table ?
    means i would like have something like
    String sql=INSERT  TABLE1 (value1) AND INSERT TABLE 2 (value 2)  // only one queryi know its wrong...but any good way ? bcoz i dont want create 2 sql query, 2 statement etc.
    is it possible ?

    Why you dont want to create 2 sql statementbcoz do not like to make 2 statements, 2 close statements......just it looks bad.
    well ok, if there is no other compact way then i will do that.
    As java-Ang asks, why do you want to do this? i want to insert into 2 different table that means i need 2 sql query . i was thinking if there is any short cut way to achieve this.
    thanks for the time

  • How to find a dependent row in the all tables using single SQL query

    hi all,
    I have created some table with master and some dependent tables.I want to mark a (row)tuple as inactive in master so that corresponding child records also should be marked as inactive.
    So i decided to mark the master and dependent records as inactive starting from master table and traverse to child tables.
    So I need SQL query to fetch all dependend records to the row(marked row in the master ) from the master table and dependent rows from the child row and to mark as flag inactive.
    can anybody help me out to build this query or any other way to mark flag as inactive ?
    Regards
    punithan

    You can find dependant tables from ALL_CONSTRAINTS, e.g:
    SQL> CREATE TABLE m (id INT PRIMARY KEY, flag VARCHAR2(1) NOT NULL);
    Table created.
    SQL> CREATE TABLE d1 (m_id REFERENCES m, flag VARCHAR2(1) NOT NULL);
    Table created.
    SQL> CREATE TABLE d2 (m_id REFERENCES m, flag VARCHAR2(1) NOT NULL);
    Table created.
    SQL> SELECT table_name, owner, status
      2  FROM   all_constraints c
      3  WHERE  c.constraint_type = 'R'
      4  AND    ( c.r_owner, c.r_constraint_name ) IN
      5         ( SELECT owner, constraint_name
      6           FROM   user_constraints
      7           WHERE  table_name = 'M'
      8           AND    constraint_type IN ('U','P') );
    TABLE_NAME                     OWNER                          STATUS
    D2                             WILLIAMR                       ENABLED
    D1                             WILLIAMR                       ENABLED
    2 rows selected.There is no SQL command to apply all updates in one go, if that's what you were looking for.
    AFAIK the word "tuple" is for mathematics and relational theory, and does not refer to a physical row in a database.

  • Single sql query-please help

    Hi experts,
    what i want to do is write a single query which will show whether a employee
    exits in the company or not.I have two tables emp and dept.There are as follows.
    SQL> select * from emp;
    NAME DEPTNO EMPNO
    xxx 10 33036
    YYY 12 2345
    ZZZ 13 678
    KKK 14 5678
    RRR 15 7865
    SQL> select * from dept;
    DEPTNO LOCATION
    10 AAA
    11 BBB
    12 CCC
    13 DDD
    what i want is it will select records from the emp table and find whether corrosponding
    deptno really exists in the dept table.If the value is found in deptno column the dept table then it will set the value
    Y other wise it will be N and all i have to do with the help of a single query.
    expected result
    name empno exists
    xxx 33036 Y
    YYY 2345 Y
    ZZZ 678 Y
    KKK 5678 N
    RRR 7865 N
    Please help.
    Regards
    Rajat

    SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM    DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST
    FROM EMP
    ORDER BY 1
    Demo
    SQL> WITH EMP AS(
      2  SELECT 'XXX' NAME , 10 DEPTNO ,33036  EMPNO FROM DUAL UNION
      3  SELECT 'YYY', 12, 2345 FROM DUAL UNION
      4  SELECT 'ZZZ', 13 ,678 FROM DUAL UNION
      5  SELECT 'KKK', 14 ,5678 FROM DUAL UNION
      6  SELECT 'RRR', 15 ,7865 FROM DUAL  ),
      7  DEPT AS(
      8  SELECT 10  DEPTNO,'AAA' DNAME FROM DUAL UNION
      9  SELECT 11 ,'BBB' FROM DUAL UNION
    10  SELECT 12 ,'CCC' FROM DUAL UNION
    11  SELECT 13 ,'DDD'FROM DUAL )
    12  SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM    DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N')
    EXIST
    13  FROM EMP
    14  ORDER BY 1
    15  /
         EMPNO NAM      EMPNO E
           678 ZZZ        678 Y
          2345 YYY       2345 Y
          5678 KKK       5678 N
          7865 RRR       7865 N
         33036 XXX      33036 Y
    SQL> Edited by: Salim Chelabi on Dec 7, 2008 4:15 AM

  • How to Handle Dynamic Pivoting with a single SQL?

    I was searching for a single SQL who can dynamically understands the pivoting members in the data, I saw several ways of doing Pivoting depending on the version, some are really hard to understand but just two options upto now seams to be flexable enough to do dynamic pivoting, right?
    1- For this option you have to write PL/SQL block to build up the dynamic single SQL query, I also find this approach very easy to understand. :)
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:766825833740
    2- 11.1 's PIVOT new feature with PIVOT XML and ANY clause, a SINGLE SQL and easy to understand but returns XMLTYPE data, another step to parse to produce the report is needed.
    http://www.oracle-developer.net/display.php?id=506
    Below is a 10g Model Clause example, but here instead of pivoting by A1-A2-A3 staticly I want to have these values by a distinc subquery for example;
    create table test(id varchar2(2), des varchar2(4), t number);
    INSERT INTO test values('A','a1',12);
    INSERT INTO test values('A','a2',3);
    INSERT INTO test values('A','a3',1);
    INSERT INTO test values('B','a1',10);
    INSERT INTO test values('B','a2',23);
    INSERT INTO test values('C','a3',45);
    commit;
    SELECT * FROM test;
    ID DES T
    A a1 12
    A a2 3
    A a3 1
    B a1 10
    B a2 23
    C a3 45
    select distinct i, A1, A2, A3
    from test c
    model
    ignore nav
    dimension by(c.id i,c.des d)
    measures(c.t t, 0 A1, 0 A2, 0 A3)
    rules(
    A1[any,any] = t[cv(i),d = 'a1'],
    A2[any,any] = t[cv(i),d = 'a2'],
    A3[any,any] = t[cv(i),d = 'a3']
    I A1 A2 A3
    C 0 0 45
    B 10 23 0
    A 12 3 1 Any advice is appreciated, thank you.

    Hi,
    You can do dynamic SQL in SQL*Plus, also.
    [Thid thread|http://forums.oracle.com/forums/thread.jspa?messageID=2744039&#2744039] shows how to pivot a table with a dynamic number of columns.

  • How to update two different tables by ony one sql query???

    Hi All,
    i need to update two different talbes in a single sql query..
    i m using the following query
    UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
    AND
    UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    i m getting the following error:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
    SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    but when i m ushin the same query in Microsoft SQL Server it executes properly:
    please help me out...

    There's no valid syntax for this, but there are some tricks you could do to achieve it.
    i) You could place an update trigger on TABLE1 to update TABLE2 automatically.
    ii) You could define a view across both tables and add an INSTEAD OF UPDATE trigger to it to maintain them.
    If I had to do this I'd choose option2, but frankly I'd just be running two updates if it really was me.

  • Need help in SQL Query: Update a row in a table & insert the same row into another table

    I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
    Thanks in Advance.

    Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
    SQL> var v_id number
    update tableA  
    set colB='ABC' 
    where colC='XYZ' 
    returning id into :v_id;
    insert into table A_History (ID, colA, colB, ColC)  
    select id, ColA, ColB, ColC  
    from tableA  
    where id = :v_id;   

  • Sql query ..need idea to write complex query

    Hi there,
    I have assigned the task to write a sql query to get the output as the below stored proc does.
    In the proc conditions are given with IF statements. I really dont know how to give all the conditions for the period in a single sql query as I'm not much used to sql quries.
    Is anyone could help me?
    Any suggestions pls . writing complicated query is nightmare. no idea . if possible help me...
    create or replace PROCEDURE vpp_station_summary_report (
    in_user_id                     IN  VARCHAR2,
    in_report_id      IN  NUMBER,
    in_time_from                IN      vppstation.avi_status_history.status_eff_date%TYPE,
    in_time_to                  IN  vppstation.avi_status_history.status_eff_date%TYPE,
    result                               OUT SYS_REFCURSOR)
    AS
    CURSOR station_loop IS
       SELECT ash.station_id,
              ash.avi_id,
              ash.state_id,
              ash.state_eff_date
       FROM   vppstation.avi_state_history ash
       JOIN   vpproadside.vpp_report_stations
         ON   vpp_report_stations.station_id             = ash.station_id
        AND   vpp_report_stations.vpp_report_seq_number  = in_report_id
       WHERE  ash.state_eff_date BETWEEN in_time_from AND in_time_to
       ORDER BY ash.station_id,
                ash.avi_id,
                ash.state_eff_date,
                ash.ash_id;
    -- cursor to find the 'entry state' i.e. the state the AVI was in AT the time of
    -- in_time_from
    CURSOR entry_state (
              state_station_id vppstation.avi_state_history.station_id%TYPE,
              state_avi_id     vppstation.avi_state_history.avi_id%TYPE,
              state_state_date vppstation.avi_state_history.state_eff_date%TYPE
    IS
       SELECT ash.state_id
       FROM   vppstation.avi_state_history ash
       WHERE  ash.station_id = state_station_id
         AND  ash.avi_id = state_avi_id
         AND  ash.state_eff_date < state_state_date
       ORDER BY ash.state_eff_date DESC,
                ash.ash_id DESC;
    current_station_id         vppstation.avi_state_history.station_id%TYPE;
    current_avi_id             vppstation.avi_state_history.avi_id%TYPE;
    current_state_id           vppstation.avi_state_history.state_id%TYPE;
    current_state_eff_date     vppstation.avi_state_history.state_eff_date%TYPE;
    period_length NUMBER;
    next_station_id     vppstation.avi_state_history.station_id%TYPE;
    next_avi_id         vppstation.avi_state_history.avi_id%TYPE;
    next_state_id       vppstation.avi_state_history.state_id%TYPE;
    next_state_eff_date vppstation.avi_state_history.state_eff_date%TYPE;
    station_open_total       NUMBER;
    station_closed_total     NUMBER;
    station_all_report_total NUMBER;
    current_station_name vpproadside.vpp_station_summary.station_name%TYPE;
    state_open       vppstation.avi_control_state_code.state_id%TYPE;
    state_closed     vppstation.avi_control_state_code.state_id%TYPE;
    state_all_report vppstation.avi_control_state_code.state_id%TYPE;
    BEGIN
    SELECT state_id
    INTO   state_open
    FROM   vppstation.avi_control_state_code
    WHERE  state_type = 'E'
    AND    state_active_ind = 'A';
    SELECT state_id
    INTO   state_closed
    FROM   vppstation.avi_control_state_code
    WHERE  state_type = 'D'
    AND    state_active_ind = 'A';
    SELECT state_id
    INTO   state_all_report
    FROM   vppstation.avi_control_state_code
    WHERE  state_type = 'S'
    AND    state_active_ind = 'A';
    current_station_id := -1;
    current_avi_id     := -1;
    current_state_id   := state_closed;
    current_state_eff_date := in_time_from;
    station_open_total       := 0.0;
    station_closed_total     := 0.0;
    station_all_report_total := 0.0;
    -- for starters - ensure that there is report data for all requested stations...
    INSERT INTO vpproadside.vpp_station_summary
          vpp_report_seq_number,
          station_id,
          station_name,
          ln_number,
          lane_name,
          station_open,
          station_close,
          station_all_report,
          station_total
      SELECT in_report_id,
             vrs.station_id,
             si.station_name,
             l.ln_number,
             l.lane_name,
             0.0,
             0.0,
             0.0,
             0.0
      FROM vpproadside.vpp_report_stations vrs
      LEFT OUTER JOIN  vpproadside.stations_installed si
        ON  si.station_id = vrs.station_id
      LEFT OUTER JOIN vppstation.lane_name l
        ON l.station_id = vrs.station_id
      WHERE vrs.vpp_report_seq_number  = in_report_id;
    -- loop over state history and update information for all stations found
    OPEN station_loop;
    LOOP
      FETCH station_loop
      INTO
            next_station_id,
            next_avi_id,
            next_state_id,
            next_state_eff_date;
      IF station_loop%NOTFOUND THEN
        next_station_id := -1;
        next_avi_id     := -1;
      END IF;
      -- if station/avi has changed take the end of the report period
      IF    (next_station_id <> current_station_id)
         OR (next_avi_id     <> current_avi_id)
      THEN
        period_length := in_time_to - current_state_eff_date;
      ELSE
        -- otherwise the start of the next period marks the end of the current period
        period_length := next_state_eff_date - current_state_eff_date;
      END IF;
      -- if we have a real station id then do some work...
      IF (current_station_id <> -1) THEN
        -- determine which category the period fits to and apply calculation
        IF current_state_id = state_open THEN
          station_open_total := station_open_total + period_length - 1;
        ELSIF current_state_id = state_closed THEN
          station_closed_total := station_closed_total + period_length - 1;
        ELSIF current_state_id = state_all_report THEN
          station_all_report_total := station_all_report_total + period_length - 1;
        ELSE
          RAISE_APPLICATION_ERROR(-20111, 'Error: found unknown state code on avi_state_history - ' || current_state_id );
        END IF;
        -- if the station/avi has changed then commit changes to db
        IF    (next_station_id <> current_station_id)
           OR (next_avi_id     <> current_avi_id)
        THEN
          UPDATE vpproadside.vpp_station_summary
          SET
              station_open       = station_open_total,
              station_close      = station_closed_total,
              station_all_report = station_all_report_total
          WHERE vpp_report_seq_number = in_report_id
          AND   station_id = current_station_id
          AND   ln_number  = current_avi_id;
          -- reset counts
          station_open_total       := 0.0;
          station_closed_total     := 0.0;
          station_all_report_total := 0.0;
        END IF;
      END IF;
      -- if we got past the last record then stop processing
      EXIT WHEN station_loop%NOTFOUND;
      -- if the station/avi is changing, get the state that was 'current' at in_time_from
      IF    (next_station_id <> current_station_id)
         OR (next_avi_id     <> current_avi_id)
      THEN
        current_state_eff_date := in_time_from;
        OPEN entry_state (
               next_station_id,
               next_avi_id,
               in_time_from
        FETCH entry_state
        INTO  current_state_id;
        IF entry_state%NOTFOUND THEN
          current_state_id := state_closed;
        END IF;
        CLOSE entry_state;
        period_length := next_state_eff_date - current_state_eff_date;
        IF current_state_id = state_open THEN
          station_open_total := station_open_total + period_length;
        ELSIF current_state_id = state_closed THEN
          station_closed_total := station_closed_total + period_length;
        ELSIF current_state_id = state_all_report THEN
          station_all_report_total := station_all_report_total + period_length;
        ELSE
            RAISE_APPLICATION_ERROR(-20111, 'Error: found unknown state code on avi_state_history - ' || current_state_id );
        END IF;
      END IF;
      current_state_id       := next_state_id;
      current_state_eff_date := next_state_eff_date;
      current_station_id     := next_station_id;
      current_avi_id         := next_avi_id;
    END LOOP;
    CLOSE station_loop;
    -- update the totals for the percentage calculation
    UPDATE vpproadside.vpp_station_summary
    SET
           station_total = station_open + station_close+ station_all_report
    WHERE   vpp_report_seq_number = in_report_id;
    -- 'fix' the totals that are still zero to avoid divide by zero errors...
    --       note: all the percentages will still come out as zero since the total
    --             was zero
    UPDATE vpproadside.vpp_station_summary
    SET
           station_total = 1.0
    WHERE  vpp_report_seq_number = in_report_id
    AND    station_total = 0.0;
    OPEN result FOR
    SELECT station_name "Site Name",
           lane_name    "Lane Name",
           TO_CHAR((station_open       / station_total) * 100.0, 'FM990.0999') || '%' "Open %",
           TO_CHAR((station_close      / station_total) * 100.0, 'FM990.0999') || '%' "Closed %",
           TO_CHAR((station_all_report / station_total) * 100.0, 'FM990.0999') || '%' "All Report %"
    FROM vpproadside.vpp_station_summary
    WHERE vpp_report_seq_number = in_report_id
    ORDER BY UPPER(station_name),
             UPPER(lane_name);
    DELETE FROM vpproadside.vpp_station_summary
    WHERE vpp_report_seq_number = in_report_id;
    END;Edited by: Indhu Ram on Mar 10, 2010 9:51 AM
    Edited by: Indhu Ram on Mar 10, 2010 9:56 AM
    Edited by: Indhu Ram on Mar 10, 2010 10:58 AM
    Edited by: Indhu Ram on Mar 10, 2010 11:12 AM

    Exactly dont know what you are asking for but I can suggest you some tips here
    - If you want to check the condition in SQL query then you can use CASE statement into select clause i.e.
    SELECT CASE when table1.a=table2.b then table1.c else table2.c END, ... more case..., table columns...
    FROM table1, table2
    WHERE
    <some conditions>
    - If you want to achive same functionality (SELECT only, not UPDATE/INSERT/DELETE) then you can convert the part of same procedure into function and can use the same function into your query by passing the parameters.
    something like this
    SELECT function_name(parameter1, parameter2....) from dual
    Hope this will help

  • How do i implement this logic in a Single SQL?

    Hi Friends!
    I’m having some problem. Hope you can share your thoughts with me.
    Let’s come to the problem
    I’m having following recordset
    S_id     t_nbr     d_id     a_dtm               b_dtm               c_dtm               create_tmstmp                    ind_f
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:48:00     22-Nov-2007 13:43:00     23-Nov-2007 01.01.14.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:58:00     22-Nov-2007 13:43:00     23-Nov-2007 01.03.00.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:30:00     22-Nov-2007 14:44:00     23-Nov-2007 01.04.05.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:31:00     22-Nov-2007 14:45:00     23-Nov-2007 01.04.07.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:31:00     22-Nov-2007 14:45:00     23-Nov-2007 01.04.22.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.05.46.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.06.01.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.07.13.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:40:00     22-Nov-2007 13:43:00     23-Nov-2007 01.08.26.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:51:00     22-Nov-2007 13:43:00     23-Nov-2007 01.09.27.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:01:00     22-Nov-2007 14:43:00     23-Nov-2007 01.10.19.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.11.46.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.12.01.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.20.13.000000000 AM     LNow,
    We have to consider a record as duplicate if the combination of a_dtm||b_dtm||c_dtm are same.
    First, we have to select all the unique record. That will be part of our output -
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:48:00     22-Nov-2007 13:43:00     23-Nov-2007 01.01.14.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:58:00     22-Nov-2007 13:43:00     23-Nov-2007 01.03.00.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:30:00     22-Nov-2007 14:44:00     23-Nov-2007 01.04.05.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:40:00     22-Nov-2007 13:43:00     23-Nov-2007 01.08.26.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:51:00     22-Nov-2007 13:43:00     23-Nov-2007 01.09.27.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:01:00     22-Nov-2007 14:43:00     23-Nov-2007 01.10.19.000000000 AM     LSecond, we have to deals with the duplicate record.
    That means the duplicate record set will be as follows -
    set 1:
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:31:00     22-Nov-2007 14:45:00     23-Nov-2007 01.04.07.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:31:00     22-Nov-2007 14:45:00     23-Nov-2007 01.04.22.000000000 AM     U
    set 2:
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.05.46.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.06.01.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.07.13.000000000 AM     Lset 3:
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.11.46.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.12.01.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.20.13.000000000 AM     LSelection of 1 record from each duplicate set:
    In case of set 1:
    Since there is no 'L' in ind_f column, we will pick the first record from it. So the selected record will be -
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:31:00     22-Nov-2007 14:45:00     23-Nov-2007 01.04.07.000000000 AM     UIn case of set 2:
    Since there is 'L' in ind_f column for the first entry from that duplicate set, we will select the first record as -
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.05.46.000000000 AM     LIn case of set 3:
    Since there is 'L' in ind_f column, we will start searching from the first record of that duplicate set. We got 'L' in the second record from that set.
    Hence we will select the following record -
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.12.01.000000000 AM     LSo, our final output will be the combination of distinct record and one record that is selected from our duplicate set. Hence the final output will be -
    S_id     t_nbr     d_id     a_dtm               b_dtm               c_dtm               create_tmstmp                    ind_f
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:48:00     22-Nov-2007 13:43:00     23-Nov-2007 01.01.14.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:58:00     22-Nov-2007 13:43:00     23-Nov-2007 01.03.00.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:30:00     22-Nov-2007 14:44:00     23-Nov-2007 01.04.05.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 14:31:00     22-Nov-2007 14:45:00     23-Nov-2007 01.04.07.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:29:00     22-Nov-2007 13:43:00     23-Nov-2007 01.05.46.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:40:00     22-Nov-2007 13:43:00     23-Nov-2007 01.08.26.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 13:51:00     22-Nov-2007 13:43:00     23-Nov-2007 01.09.27.000000000 AM     U
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:01:00     22-Nov-2007 14:43:00     23-Nov-2007 01.10.19.000000000 AM     L
    306     1107     YYZ     22-Nov-2007 12:32:00     22-Nov-2007 15:29:00     22-Nov-2007 15:43:00     23-Nov-2007 01.12.01.000000000 AM     LI've already identify the duplicate records in a single SQL query. But, unable to implement this selection approach of single record from the duplicate set.
    How do i achive this in a single SQL?
    By the way,
    I'm using Oracle 9i.
    Thanks for your efforts in advance.
    Regards.
    Satyaki De.
    Oops! You are right. I've made the change.
    N.B.: The duplicate sets will form based on the create_tmstmp field

    Hi, Satyaki.
    Your query should be very simple:
    SQL> with t as
      2  (select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:48:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.01.14.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
      3   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:58:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.03.00.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
      4   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 14:30:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 14:44:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.04.05.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'U'     ind_f from dual union all
      5   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 14:31:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 14:45:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.04.07.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'U'     ind_f from dual union all
      6   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 14:31:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 14:45:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.04.22.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'U'     ind_f from dual union all
      7   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:29:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.05.46.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
      8   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:29:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.06.01.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'U'     ind_f from dual union all
      9   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:29:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.07.13.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
    10   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:40:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.08.26.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
    11   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 13:51:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 13:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.09.27.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'U'     ind_f from dual union all
    12   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 15:01:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 14:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.10.19.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
    13   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 15:29:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 15:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.11.46.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'U'     ind_f from dual union all
    14   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 15:29:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 15:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.12.01.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual union all
    15   select 306 S_id, 1107 t_nbr, 'YYZ'     d_id, to_date('22-Nov-2007 12:32:00','dd-mon-yyyy hh24:mi:ss') a_dtm,     to_date('22-Nov-2007 15:29:00','dd-mon-yyyy hh24:mi:ss') b_dtm, to_date('22-Nov-2007 15:43:00','dd-mon-yyyy hh24:mi:ss')     c_dtm,     to_timestamp('23-Nov-2007 01.20.13.000000000 AM','dd-mon-yyyy hh:mi:ss.ff AM')     create_tmstmp, 'L'     ind_f from dual)
    16   --
    17   select *
    18     from (select t.*,
    19                  row_number() over(partition by s_id, t_nbr, d_id, a_dtm, b_dtm, c_dtm order by nullif(ind_f, 'U') nulls last, create_tmstmp) rn
    20             from t)
    21    where rn = 1
    22  /
          S_ID      T_NBR D_ID A_DTM       B_DTM       C_DTM       CREATE_TMSTMP                                     IND_F         RN
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.05.46.000000000 AM                   L              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.08.26.000000000 AM                   L              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.01.14.000000000 AM                   L              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.09.27.000000000 AM                   U              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.03.00.000000000 AM                   L              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.04.05.000000000 AM                   U              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.04.07.000000000 AM                   U              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.10.19.000000000 AM                   L              1
           306       1107 YYZ  22.11.2007  22.11.2007  22.11.2007  23-NOV-07 01.12.01.000000000 AM                   L              1
    9 rows selected
    SQL> \PS BTW you're not a newbie in the forum, please, post WITH clause or CREATE/INSERT statement for your data next time.

  • Calculations Using SQL Query

    Hi All,
    I am using Oracle Database Version 11.2.
    I have a formula (A-B)/[(A-B)/10]. The tables that are holding the rows for this calculations are given below:
    ROWS_TAB
    ====== ===================
    Row          Amount
    ====== ===================
    A            5000
    B            -5000
    FORMULA_TAB
    ======== =========== ======== =============
    | ROW#  | Operator            | ROW        |   CONSTANT   |
    ======== =========== ======== =============
    | 10        |     E                   |      A       |                         |
    | 20        |     -                    |     B        |                         |
    | 30        |     E                   |      A       |                         |
    | 40        |     -                    |     B        |                         |
    | 50        |     /                    |               |      10                |
    | 60        |    /                     |               |                          |
    ======== =========== ======== =============
    The operator E starts a new calculation. The above formula has two sub-expressions thereby the table has two rows with E. Minus denoted by -, Plus denoted by +, Multiply denoted by *, and Division denoted by /.
    I want to write single SQL query to perform this calculation. Is it achievable in SQL?
    The scripts used to generate the tables are as below:
    create table ROWS_TAB
    (row_name VARCHAR2(1),
    amount NUMBER);
    create table FORMULA_TAB
    (row# NUMBER,
    operator VARCHAR2(1),
    row_name VARCHAR2(1),
    constant NUMBER);
    INSERT INTO ROWS_TAB VALUES('A', 5000);
    INSERT INTO ROWS_TAB VALUES('B', -5000);
    INSERT INTO FORMULA_TAB VALUES(10, 'E','A',null);
    INSERT INTO FORMULA_TAB VALUES(20, '-','B',null);
    INSERT INTO FORMULA_TAB VALUES(30, 'E','A',null);
    INSERT INTO FORMULA_TAB VALUES(40, '-','B',null);
    INSERT INTO FORMULA_TAB VALUES(50, '/','',10);
    INSERT INTO FORMULA_TAB VALUES(60, '/','','');
    Can anyone help in writing SQL query....
    Thanks in advance
    Best Regards
    Bilal

    As Frank said, it would be much easier to simply input the formula. Then, assuming you have OLAP option:
    variable formula varchar2(30)
    exec :formula := '(A-B)/((A-B)/10)';
    with t as (
               select  *
                 from  rows_tab
                 model
                   dimension by(row_number() over(order by row_name) r)
                   measures(
                            row_name,
                            amount,
                            count(*) over() cnt,
                            cast(:formula as varchar2(4000)) formula
                   rules(
                         formula[any] order by r = replace(nvl(formula[cv() - 1],formula[cv()]),row_name[cv()],amount[cv()])
    select  :formula || ' = ' || dbms_aw.eval_number(formula) result
      from  t
      where r = cnt
    RESULT
    (A-B)/((A-B)/10) = 10
    SQL>
    And if you do not have OLAP, you could use xquery:
    with t as (
               select  *
                 from  rows_tab
                 model
                   dimension by(row_number() over(order by row_name) r)
                   measures(
                            row_name,
                            amount,
                            count(*) over() cnt,
                            cast(:formula as varchar2(4000)) formula
                   rules(
                         formula[any] order by r = replace(nvl(formula[cv() - 1],formula[cv()]),row_name[cv()],amount[cv()])
    select  :formula || ' = ' || xmlquery(replace(formula,'/',' div ') returning content) result
      from  t
      where r = cnt
    RESULT
    (A-B)/((A-B)/10) = 10
    SQL>
    SY.

  • Sql query to update record?

    hi1
    i have 1000 rows in my table that are not unique. i have added a new column named sno.initially that contains null values. Now i want to update the table with sno contains serial no. from 1 to 1000 in a single SQL query
    please help
    Thanks
    Harinder

    hi1
    i have 1000 rows in my table that are not unique. i
    have added a new column named sno.initially that
    contains null values. Now i want to update the table
    with sno contains serial no. from 1 to 1000 in a
    single SQL query
    please help
    Thanks
    HarinderIt will work..
    Update <table_name> set <column_name> = ROWNUM
    whether the records are duplicate or not...

  • A simple SQL query question

    I have an interesting problem and wondering how I can get this result in a single SQL query:
    Here is table emp has data with a row for every year since the employee joined with the salary paid that particular year with following columns:
    emp (
    id varchar2(10),
    name varchar2(25),
    interested_year date,
    salarypaid number(10)
    I would like to print the results as follows:
    id name previousyear_salarypaid currentyear_salarypaid
    x xxxxx xxxxxx xxxxx
    Is this possible to do? I have tried to simplify my actual problem so I hope I have included all necessary details.

    Just to clarify, the columns mentioned in the results are
    previousyear_salarypaid is nothing but
    salarypaid where interested_year = '2007'
    currentyear_salarypaid is nothing but
    salarypaid where interested_year = '2006'

  • Sql query to list menus, submenus and function-names for all resp

    Hi,
    Please let me know one single sql query to list all the menus, submenus and user-function-names attached for all responsibilities
    Thanks...

    Hi,
    See the following threads.
    How to find All The Responsibilities with a specific Menu
    How to find All The Responsibilities with a specific Menu
    SQL query
    SQL query
    Regards,
    Hussein

Maybe you are looking for

  • Missing loops?

    Hello, I can't find my loops! I have GB2 and an iMac G5 and my loops are not showing up in the loop browser. I still have the folder with all the loops in it, however, when I try to drag it into the loop browser, nothing happens. The computer says th

  • Question about mapping logical sources to dimensions

    1) On my physical layer I have one fact table (FACTS_DETAILS) linked with CATEGORY dimension table. Other fact tables (aggregated data) don't linked with this CATEGORY dimension with physical joins. 2) On my BMM layer I have mapped my dimension "Cate

  • Paypal tricked me into using a back account instead of my credit card

    I have always used my credit card when buying from ebay, and then suddenly paypal used my bank account without my permission. How do I get that back account out of paypal? It does not have enough money in it to make purchases, and I do not want a ban

  • IDoc field and SAP Table field

    I want to find out which SAP table field is populating the given IDoc segment without getting into ABAP code? Do we have something like "Where-used" list? On the reverse side, If I want to know which SAP Table field the incoming IDoc segement is post

  • WD passport not found on MBA but on windows

    Hey, I've had a MBA and a 750gb WD my passport since august. the harddrive has worked fine till this morning when it wouldnt show up on my MBA or my brothers macbookpro, yet shows up on a windows unit?? this happened just after a software update to 1