Compare the same value of the column

Hello
I have table as below
ID      Date     Department
1   25-Jul-08        XX
2   26-Jul-08        XX
3   22-May-08        YY
4   23-May-08        YY
5   24-May-08        YY
6   13-Jun-08        ZZ
7   14-Jun-08        ZZ
Now, I need to compare the date of each Department and return the case to higher-value Date only in this Department. my result set must therefore as below:
ID      Date     Department
2   26-Jul-08        XX   
5   24-May-08        YY
7   14-Jun-08        ZZ
any idea?

Is only one record in the Department with the highest date?
If so, use aggregate KEEP statement:

SELECT max (id) to Dungeon code (dense_rank of first order of date # desc).
Max(date#), Department of
Of

Group of Department;

If several whan a line with the date of the highest can exist in a single Department, use

SELECT id, date #, Department
de)
SELECT id, date #, Department, dense_rank() on Dr. (depatyment date order partition # desc)
Of


)
where dr = 1

(Not tested!)

Rgds.

Tags: Database

Similar Questions

  • Compare the column values for multiple lines

    I am new to oracle and I have a requirement to compare the values of column across multiple lines.  If all column values are the same, I want to display that value, if the columns are not the same, I need to display 'no match' as value.   I need id to group values and display a status value based on the above logic.   Can anyone offer assistance with dispalying the result expected below?

    Sample

    Table

    State ID

    1         S

    2         L

    1         S

    2          S

    expected results

    State ID

    1         S

    2 no match


    Hello

    That's what you asked for:

    SELECT id

    CASE

    WHEN COUNT (DISTINCT status) > 1

    THEN "no match."

    For ANOTHER MIN (status)

    The END as status

    T

    GROUP BY id

    ;

    Want that if each State ID is NULL?  The CASE expression above returns NULL in this situation.

  • Find the same value in different columns

    Hello

    I'm trying to figure out how I would get the same value in the same row but in different columns. For example, in the table sometimes report the name is the same as the description. I would like to find all the lines where this is the case.

    Thank you

    Name of the report
    Description
    Date
    Time
    Report 1Report 1DelalandeTTTT
    Report 2Billing reportDelalandeTTTT
    Report 3Report 3DelalandeTTTT

    Hello

    Is that what you want?

    SELECT *- or whatever the columns that you want to

    FROM table_x

    WHERE description = report_name

    ;

    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.
    Explain, using specific examples, how you get these results from these data.
    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

  • By comparing the values in the same column

    Hello

    I have a requirement to do the following:

    The guest of the dashboard has two drop downs as 'Acct number 1' and others as 'Acct number 2 ". Both are the same column from the database. When two different values are chosen from the prompt, it should produce a report with the following 5 colomns, 'ACCT1', 'SALES AMOUNT ACCT1', "ACCT2", "SALES AMOUNT ACCT2", "DIFFERENCE".

    I tried to use a variable of presentation in the command prompt and it fills my column pther having the same value I have input for the first prompt.

    How can I do this? Thanks for your time and your help.

    Hello

    You can try it at the level of the report.

    * Ensure that you have set your guests with different effects. Suppose that the two PVs are acc1 and acc2.
    * Report, add below filter
    Account number is equal to @{acc1} {defualtvalue}
    OR
    Account number is equal to @{acc2} {defualtvalue}
    This will filter the report by the two account numbers.
    * Now apply below in your fx of all columns.

    "ACCT1: ' @{acc1} {defualtvalue}"
    ACCT1 SALES AMOUNT: FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc1} {defualtvalue}'))
    "ACCT2: ' @{acc2} {defualtvalue}"
    ACCT2 SALES AMOUNT: FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc2} {defualtvalue}'))
    DIFFERENCE: FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc1} {defualtvalue}'))-FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc2} {defualtvalue}'))

    Thank you

  • update other items with the same value when when the column contains Y

     
    CREATE TABLE TEST 
       (     "QUATINTY" NUMBER(17,2), 
         "AMOUNT" NUMBER(17,2), 
         "ERRORRED" VARCHAR2(16 BYTE), 
         "PO" VARCHAR2(12 BYTE), 
         "LINE" VARCHAR2(10 BYTE), 
         "SEQ" VARCHAR2(14 BYTE), 
         "INVOICE" VARCHAR2(16 BYTE)
       ) 
    
    Insert into TEST (PO,QUATINTY,AMOUNT,ERRORRED,LINE,SEQ,INVOICE) values ('123',5,50,'Y','1','1','inv1');
    Insert into TEST (PO,QUATINTY,AMOUNT,ERRORRED,LINE,SEQ,INVOICE) values ('123',5,50,null,'1','2','inv1');
    Insert into TEST (PO,QUATINTY,AMOUNT,ERRORRED,LINE,SEQ,INVOICE) values ('125',5,50,null,'1','1','inv2');
    Insert into TEST (PO,QUATINTY,AMOUNT,ERRORRED,LINE,SEQ,INVOICE) values ('125',4,50,null,'1','2','inv2');
    If you notice the table above which im trying to Edifier is updated the errorred column with 'Y' if the po and invoice are the same and have a 'Y' on the wrong column.
    in other words, I should finish with "Y" in the column for INV1 errorred.
    Can someone point me in the right direction, I can't for the life of me figuered it out.

    Hello

    Here's one way:

    UPDATE     test
    SET     errorred     = 'Y'
    WHERE     NVL (errorred, 'N') != 'Y'
    AND     (po, invoice)          IN (
                              SELECT  po, invoice
                         FROM      test
                         WHERE      errorred  = 'Y'
                               )
    ;
    

    This requires that the po and invoice are not NULL. If a column can be NULL, then the solution might be a little messier, according to the results you want, but only a little. Post some sample data (with null values) which shows what types of situations, you need manage, and the results of the SAMPLES.

  • Compare the values of the XMLType column to two different lines using XMLDiff in GR 11, 2

    I have a table of data with a row of XMLType and I need a way to compare the XML data against the other. I guess I could use a function and return a XMLDIFF base output to the caller, but the function logic is a bit fuzzy. Would be nice to format the output finally in a table format.

    I looked on http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions241.htm#SQLRF20025 and output in a format of table as shown in Re: how to find compare and identify between xmldocs .

    I ran across some examples do not explain the best way to compare the XML code that is in the best performing XMLType column.

    Any help would be appreciated.

    Are you referring to different rows in the same table or different tables or?

    Basically, you need to change the example of Odie so that the XMLDiff retrieves the XML from places in Pb, say something like

    XMLDIFF(SELECT aXml FROM table WHERE ...,
            SELECT bXml FROM table WHERE ...)
    

    This allows to avoid bringing the XML of the DB in the client code.

    Don't know if that's what you're looking for, but hopefully it helps a little.

  • Map of the same different value of the column in different column based on conditio

    Hi experts,

    We source as Oracle tables and target also Oracel tables.

    Source
    --------
    Column1 | Column2 | Column3

    Goal
    ---------
    trg1 | trg2

    I need to
    Insert the value of Column1 in trg1 where column2 = 'xxx '.
    Insert the value of Column1 in trg2 where Column3 = "yyy".

    After giving the conditions on mapping, the where conditions become clubed with and I get a different value to what is excluded. As the same way, I have the same scenario for most of the columns in my target table. Suggest me how do.

    Thanks in advance.

    Hello

    to do everything in a single interface without performance issue you could do a join like this

    Source.col2 = source2.src1 or Source.col2 = Source2.src2

    This mapping and

    Target.trg1

    CASE WHEN Source.col2 = Source2.src1 THEN
    Source.Col1
    ANOTHER NULL
    END

    Target.TRG2

    CASE WHEN Source.col2 = Source2.src2 THEN
    Source.Col1
    ANOTHER NULL
    END

  • How can I compare the value of column within the COUNT() function?

    I want to compare the value of the column within the COUNT() function as below how ever it gives me the error. I want to calculate the percentage, how can I do this task?
    Thank you.


    SELECT department_id
    , COUNTY (salary < 250000) / COUNT (*)
    OF plch_employees
    GROUP BY department_id
    ORDER BY department_id;
    SELECT  department_id.
            COUNT(CASE WHEN salary < 250000 THEN 1 END) / COUNT(*)
      FROM  plch_employees
      GROUP BY department_id
      ORDER BY department_id
    /
    

    SY.

  • An update on an index column with the same value generates an index to the top

    An update on an index column with the same value generates an update of the index?


    Thank you

    In addition to my previous answer, see also

    http://orainternals.WordPress.com/2010/11/04/does-an-update-statement-modify-the-row-if-the-update-modifies-the-column-to-same-value/

    Riyaj Shamsudeen has this to say:
    "+ We have an index on this column v1 and we update this column indexed too." Oracle was updating the indexed column? N ° if the values match the level of the indexed column, then the code of RDBMS isn't up-to-date index, a feature for optimization again. Only the row of table is updated, and the index is not updated. + "

    Hemant K Collette

  • Fill two empty columns with the values in a column (all in the same table)

    Can someone point me in the right direction? I want to fill the column prefix and suffix with the AcctNum data.

    "Prefix is the part of the number before the '-' and the suffix is everything after the '-'. '. Write a SQL command to fill the column prefix and suffix.
    *Accounts* 
    
    AcctNum   Prefix   Suffix
    -------   ------   -------
    123-0097
    X089-056
    123-0097
    123-0098
    F3377-D
    X089-057
    X089-058
    3-009712
    It is supposed to look like this:
    *Accounts* 
    
    AcctNum   Prefix   Suffix
    -------   ------   -------
    123-0097    123     0097
    X089-056
    123-0097
    123-0098
    F3377-D
    X089-057
    X089-058
    3-009712
    That's what I came with, but it does not work because it is basically putting multiple values into a single cell:
    update accounts
         set prefix=(select substr(acctnum, 1, instr(acctnum,'-')-1) from accounts),
         suffix=(select substr(acctnum, instr(acctnum, '-')+1) from accounts)
         where acctnum=(select prefix||'-'||suffix from accounts);
    I want this query is incredibly easy and I have forget something. Any help is greatly appreciated.

    Published by: 885913 on September 18, 2011 12:53
    UPDATE accounts a
    SET    ( prefix, suffix ) = (SELECT Substr(acctnum, 1, Instr(acctnum, '-') - 1),
                                        Substr(acctnum, Instr(acctnum, '-') + 1)
                                 FROM   accounts b
                                 WHERE  a.acctnum = b.acctnum);
    
  • Take the values of this same line of a column max

    Hello

    I did a group by in a query to date max of straight, but I need to take on values of that same line with this maximum value.

    Max (to_date(fec_ini_vigencia_costo,'DD/mm/YYYY')) is the line I want to take

    and

    -max (mto_precio_venta_cm_iva),
    -fec_fin_vigencia_costo,
    -l.CND_TRASPASADO_PRECIO

    the values I want to take advantage of this line

    select p.item_orms, 
           item_ebs, 
           description, 
           zone_id, 
           max(to_date(fec_ini_vigencia_costo,'DD/MM/YYYY')) as fecha_inicio,
           -- max(mto_precio_venta_cm_iva),
           -- fec_fin_vigencia_costo,
           -- l.CND_TRASPASADO_PRECIO
    from precios9 p,
         cmp_lineas_cotizacion_suc l,
         LCM.CMP_ENCABEZADO_COTIZACION d 
    where p.zone_id = 1
         and l.cod_producto = p.item_ebsi'
         and d.NUM_COTIZACION_ORCL = l.NUM_COTIZACION_ORCL
         and l.cod_sucursal in (125,89,90,92,95,97,99,101,104,106,108,110,112,115,83,85,
                               87,88,91,93,94,96,98,100,102,103,107,109,111,113,114,116,
                               117,120,123,124,128,130,132,134,135,133,131,129,118,182)
    group by p.item_orms, item_ebs, description, zone_id

    Buon Giornio!

    Here are two ways to do it. First of all, using analytical functions and then with a subquery.

    I took your sample data and converted into a WITH statement, so I could test my queries. The SQL code that you need to write is near the bottom.

    WITH dta AS (
    SELECT 100124238 AS ITEM_ORMS,1.1073131 AS ITEM_EBS,'Comino Badia Molido 28Gr' AS DESCRIPTION,1 AS ZONE_ID,TO_DATE('03/02/2007','dd/mm/yyyy') AS FEC_INI_VIGENCIA_COSTO,1.7 AS MTO_PRECIO_VENTA_CM_IVA,TO_DATE('08/12/2010','dd/mm/yyyy') AS FEC_FIN_VIGENCIA_COSTO,'Si' AS CND_TRASPASADO_PRECIO FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('09/06/2008','dd/mm/yyyy'),24.9,TO_DATE('13/04/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/04/2009','dd/mm/yyyy'),31.95,TO_DATE('01/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('01/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('11/06/2009','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('11/06/2009','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'Si' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL UNION ALL
    SELECT 100132641,1.1054401,'Crema Meggle Chantilly Natural 250Gr',1,TO_DATE('13/05/2010','dd/mm/yyyy'),62,TO_DATE('13/05/2010','dd/mm/yyyy'),'No' FROM DUAL
    )
    SELECT DISTINCT
       MAX ( FEC_FIN_VIGENCIA_COSTO ) OVER () FEC_FIN_VIGENCIA_COSTO
      , FIRST_VALUE ( MTO_PRECIO_VENTA_CM_IVA ) OVER ( ORDER BY FEC_FIN_VIGENCIA_COSTO DESC  ) AS MTO_PRECIO_VENTA_CM_IVA
      , FIRST_VALUE (  CND_TRASPASADO_PRECIO  ) OVER ( ORDER BY FEC_FIN_VIGENCIA_COSTO DESC  ) AS FEC_FIN_VIGENCIA_COSTO
    FROM dta
    ;
    
    FEC_FIN_V MTO_PRECIO_VENTA_CM_IVA FE
    --------- ----------------------- --
    08-DEC-10                     1.7 Si
    
    1 row selected.
    

    And here's the subquery

      << omitted the WITH clause here, just to save space >>
    
    SELECT
      MTO_PRECIO_VENTA_CM_IVA
      , FEC_FIN_VIGENCIA_COSTO
      , CND_TRASPASADO_PRECIO
    FROM dta
      WHERE FEC_FIN_VIGENCIA_COSTO = ( SELECT  MAX(  FEC_FIN_VIGENCIA_COSTO )  FROM dta )
    ;
    
      MTO_PRECIO_VENTA_CM_IVA FEC_FIN_V CN
      ----------------------- --------- --
                          1.7 08-DEC-10 Si
    
    1 row selected.
    

    I would caution you to be careful with either technique: you have not specified a deterministic sort. There are a lot of records with the same values in this field. If if were not for the record for December 8, 2010, the highest value would be on May 13, 2010, and there are 22 records with that value. This means that Oracle would have to break the tie.

  • A statement UPDATE changes the line if the update changes the column even value?

    HI -.

    I have a main classification and the corresponding audit table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211

    Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time. He is not able to determine that the value is the same.

    My goal is to load the audit table data if the value in a cell in the main table is really have changed.

    A statement UPDATE changes the line if the update changes the column even value?

    Best regards

    I have a main Table and the corresponding Audit Table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211

    Why?

    You try to resolve what made you what are the PROBLEM that select as the solution?

    Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time.

    Yes - it is EXACTLY what you say that you wanted to do and EXACTLY what the code does in this article.

    He is not able to determine that the value is the same.

    I think you mean that the code does NOT check if the value is the same. You can certainly change the code to do this check. But I have a question to start with your need for such a solution.

    My goal is to load the audit table data if the value in a cell in the main table is really have changed.

    OK - then modify the code to check EACH COLUMN and compare its NEW value to the OLD value and insert only the table of audit if SOME (or columns you care specifically) have changed.

    A statement UPDATE changes the line if the update changes the column even value?

    It depends on what you mean by 'change the line '. Of course to update a column with the SAME value does not change the resulting data value.

    But the physical structure of the line, the location of the pieces of line and information in the header block (YVERT, etc.) will change. And, as others have said Oracle doesn't know and doesn't care, so if the new value of a column is the same as the old value will create redo, undo and the rest.

    Start over and tell us what PROBLEM you're trying to solve. Then we can help you find the best way to solve it.

  • The column that does not match when comparing two records

    Hi all

    We try to compare two tables and find the differences. So if two records (1 of each table) have same PK but not always matching because of some columns, then we would display this columnname. For example:

    Table 1

    PK Parent Child Property1 Property2
    1AA1P1PR1
    2BB1P2oraPR2
    3CC1P3SRP

    Table 2

    PK Parent Child Property1 Property2
    1AA1P1PR1
    2BB1P2PR2
    3CC1P3PR4

    In the above example when I compare 2 tables all matches except Property2 online n ° 3. Thus, we would like to get an output like:

    PK Column_Mismatch
    3Property2 (this must be the name of the column that does not match)

    Appreciate the help.

    Thank you

    Andy

    Hi, Andy.

    Andy1484 wrote:

    Hi all

    We try to compare two tables and find the differences. So if two records (1 of each table) have same PK but not always matching because of some columns, then we would display this columnname. For example:

    Table 1

    PK Parent Child Property1 Property2
    1 A A1 P1 PR1
    2 B B1 P2 oraPR2
    3 C C1 P3 PR3

    Table 2

    PK Parent Child Property1 Property2
    1 A A1 P1 PR1
    2 B B1 P2 PR2
    3 C C1 P3 PR4

    In the above example when I compare 2 tables all matches except Property2 online n ° 3. Thus, we would like to get an output like:

    PK Column_Mismatch
    3 Property2 (this must be the name of the column that does not match)

    Appreciate the help.

    Thank you

    Andy

    Why you don't want no matter what exit for pk = 2?  Property2 does not correspond either to pk.

    What happens if the 2 columns (or more) do not match?  The following query would produce a list delimited, such as ' parents; PROPERTY2 '.

    WITH got_mismatch AS

    (

    SELECT pk

    , CASE WHEN t1.parent <> t2.parent THEN '; PARENT' END

    || CASE WHEN t1.child <> t2.child THEN '; CHILD ' END

    || CASE WHEN t1.properry1 <> t2.property1 THEN '; PROPERTY1 ' END

    || CASE WHEN t1.properry2 <> t2.property2 THEN '; PROPERTY2 ' END

    AS the offset

    FROM table_1 t1

    JOIN table_2 t2 ON t2.pk = t1.pk

    )

    SELECT pk

    , SUBSTR (incompatibility, 3) AS column_mismatch

    OF got_mismatch

    WHERE mismatch IS NOT NULL

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

    The query above does not count NULL values as inadequate.  If you want that, the same basic approach will work, but you can use DECODE instead of <> to compare columns.

    What happens if a pk exist in a table, but not the other?  You want an outer join, where I used an inner join above.

  • Disqualification: Compare the value list in another Table

    I'm relatively new to the Disqualification.

    I use the 11.1.1.7 version.

    I have 2 tables Oracle.  Table1.FieldA does not have a foreign key constraint (but should be) at Table2.FieldB.

    I created a snapshot for Table1 that includes FieldA.

    I created another cliché to Table2 which includes FieldB.

    I am trying to compare the Table1.FieldA with Table2.FieldB value to make sure that there is.

    I can think of a few processors that I could, but they seem to compare a value with another value in the same snapshot (table).

    Any advice would be helpful.


    Thank you.

    Ray

    Hello

    Use the search check if you want to just check between the tables. According to the reference database, you need create a list of choices on the table (can be either staged as you, or just a list of external choice provided the lookup columns are indexed). Use Lookup and return if you want to import data in the other table in your process. You can control if you want a 1:1 or from a 1:M relationship, and if you go back several records, you can use split chronogram: table with all the paintings of entry to create an intermediate join process.

    Mike

  • by comparing the two date columns

    I want to compare two values of the column of the same table. Both the date and time part. but I would like to compare with only the date portion. I want these files where two dates are not same. but it includes a part of the time in the comparison with the following query.
    select * from reporttransactions a,  reporttransactions b  
    where trunc ( to_date(a.TRANSACTION_DATE, 'DD/MM/YYYY' )) <> trunc (to_date(b.TRANSACTION_CREATION_DATE,'DD/MM/YYYY' ))
    any suggestion

    I think it's true,

    When: WHERE TRUNC (A.TRANSACTION_DATE) = TRUNC (B.TRANSACTION_CREATION_DATE)

    223605062     3247     0     0     -     215     1     215     8     8     0     215PKI     01/09/2012     01/09/2012
    223605056     5733     0     0     -     131     1     131     9     9     0     131RAS     01/09/2012     01/09/2012
    223605050     4568     0     0     -     132     1     132     5     5     0     132FSH     01/09/2012     01/09/2012
    223604993     1623     0     0     -     176     1     176     8     8     0     176TCL     01/09/2012     01/09/2012
    

    When: WHERE TRUNC (A.TRANSACTION_DATE)! = TRUNC (B.TRANSACTION_CREATION_DATE);

    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    225833757     9113     0     0     -     161     1     161     3     3     0     161CBE     16/09/2012     16/09/2012
    

    What's wrong?

Maybe you are looking for