An IF statement, based on a unique combination of records from a table of encoding

I want to capture the unique combination (col1, col2, col3) from a table one. If these figures obtained from a combination of col1, col2, col3 exceed a number of 1 and then do something else.

SELECT a.col1,a.col2,a.col3,count(*)
FROM table a
group by a.col1,a.col2,a.col3
having count(*) > 1

Hello

I don't know what you are looking for. Is this something like that?

SELECT    col1, col2, col3
,        COUNT (*)          AS cnt
,       CASE
          WHEN  COUNT (*)  > 1
          THEN  'Somehting'
          ELSE  'Something else'
       END               AS opt
FROM        table_a
GROUP BY  a.col1, a.col2, a.col3
;

Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
In the case of a DML (such as INSERT) operation the sample data should show what look like the paintings before the DML, and results will be the content of the or a modified tables after the DML.
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 {message identifier: = 9360002}

Tags: Database

Similar Questions

  • How to delete records from a table that has a composite unique key duplicate

    Hello
    I get the customer data from various sources in the staging of the table where I insert in the database table where the combination of two columns is considered as a unique key. But there is a possibility of duplicates. How to find duplicates in a SQL or pl/sql

    Thank you
    Manoi.

    Kassa,

    You can see the duplicates by using the following query...

    sql> select * from temp_rajesh;
    
          COL1       COL2 MESSAGE
    ---------- ---------- ------------------
           100        200 message
           100        200 message2
           300        400 message3
           400        500 message 4
    
    sql> select col1, col2, count(*)
      2     from temp_rajesh
      3       group by col1, col2
      4         having count(*) > 1;
    
          COL1       COL2   COUNT(*)
    ---------- ---------- ----------
           100        200          2
    

    -If in the case of duplicate records, you should see only the duplicates (according to some timestamp etc., you can use the functinon row_number analytic..)

      1  select col1, col2 from (
      2  select col1, col2,
      3         row_number() over (partition by col1, col2
      4                            order by message) rn
      5    from temp_rajesh)
      6*   where rn > 1
    sql> /
    
          COL1       COL2
    ---------- ----------
           100        200
    

    In the above example, I use message to order, you can replace it with activity_timestamp or the insertd_date according to your logic... when there are two records... one that you choose to duplicate.

    Thank you
    Rajesh.

    Published by: Rajesh Chamarthi on November 20, 2009 12:05 AM (added for example)

  • update of column based on the sum of the data from another table

    I have two tables:

    Table1 (col1, col2, col3, col4, val1, status) Table2 (col1, col2, col3, col4, val2)

    For Table1 and Table2, column (col1, col2, col3, col4) are the primary key of composit.

    Table2 could have duplicated lines, that's why I want to group by (col1, col2, col3, col4) and sum (val2)

    After that, I want to update Table1.val1 with the value of sum (Table1.val2) where Table1.col1 = Table2.col1 and Table1.col2 = Table2.col2 and Table1.col3 = Table2.col3 and Table1.col4 = Table2.col4 and status = 'V '.

    I did something like this:

    UPDATE Table1 SET val1 = (

       

    WHERE Table1.col1 = t_sommevbrute.col1 and Table1.col2 = t_sommevbrute.col2 and Table1.col3 = t_sommevbrute.col3 and Table1.col4 = t_sommevbrute.col4)

    Could someone help me please? Thank you

    merge into table1 t1

    using (select col1, col2, col3, col4, sum (val2) val2

    from table2

    Group

    by col1, col2, col3, col4) t2

    on (t1.col1 = t2.col1 t1.col2 = t2.col2 and t1.col3 = t2.col3 and t1.col4 = t2.col4 and)

    When matched then

    update set t1.val1 = t2.val2;

  • Creation of the unique combinations

    Hello

    I am trying to create unique combinations of two numbers, for example: (1,2), (1,3)... etc by using the following code:

    DECLARE

    v_count number (4): = 0;

    BEGIN

    I'm in 1.5

    LOOP

    J in 1.5

    LOOP

    v_count: = v_count + 1;

    dbms_output.put_line (v_count |'-> ('| i | ',' | j |') ');

    END LOOP;

    END LOOP;

    END;

    But here, I am unable to stop the same combinations of repeat - (1,2), (2,1) or (2,3), (3,2).

    Can someone help me figure out how to stop the same combinations of repeat.

    For example: if (1.2) is there then (2.1) should not be there.

    Concerning

    Hawker

    DECLARE

    v_count number (4): = 0;

    BEGIN

    I'm in 1.5

    LOOP

    FOR j in i... 5

    LOOP

    v_count: = v_count + 1;

    dbms_output.put_line (v_count |') -> ('|| i||','|| j||')');

    END LOOP;

    END LOOP;

    END;

    /

    1-> (1.1)

    2-> (1,2)

    3-> (1,3)

    4-> (1,4)

    5-> (1.5)

    6-> (2.2)

    7-> (2,3)

    8-> (2.4)

    9-> (2.5)

    10-> (3.3)

    11-> (3,4)

    12-> (3.5)

    13-> (4,4)

    14-> (4,5)

    15-> (5.5)

  • Hi all. I have adobe PS cc and I want to upgrade for PS and lightroom. How can I go about it without having to pay for two and a unique combined price? Thank you

    Hi all. I have adobe PS cc and I want to upgrade for PS and lightroom. How can I go about it without having to pay for two and a unique combined price? Thank you

    You should talk to Adobe Support by chat or phone when they are available (not usually weekend) because they might be able to help to organize the change without any cancellation penalties.

    Phone/Chat support - for the link below, click on the still need help? the option in the blue box below and choose the option to chat...
    Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache.  If it fails to connect, try to use another browser.

    Creative cloud support (all creative cloud customer service problems)
    http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN )

    Otherwise what you would normally do, it is first of all visit the following page to see what you can do on your own

    Manage your membership and your payment. Creative cloud

    https://helpx.Adobe.com/x-productkb/policy-pricing/membership-subscription-troubleshooting-creative-cloud.html

    and then if necessary undo the current plan (penalties being possible) and subscribe to the new.

    Cancel your subscription or membership. Creative cloud

    https://helpx.Adobe.com/x-productkb/policy-pricing/cancel-membership-subscription.html

  • Update statement based on some files

    Hello all;

    I tested on a simple case and it seems to work but I don't know why it doesn't work on my major case...

    What I'm trying to do, it is essentially update of a particular line in a certain table based on information from another table...

    See the example below.
    create table t 
    ( Id varchar2(10),
     place char (1)
     );
    insert into t
       (id, place)
     values
       ('A1', 'B');
    
    insert into t
       (id, place)
     values
       ('A2', 'C');
       
    insert into t
       (id, place)
     values
       ('A3', 'D');
    insert into t
       (id, place)
    values
       ('A4', ' '); 
     
     create table t2
     (
     id varchar2(10),
     old_place char(1),
     new_place char(1)
     );
    insert into t2
       (id, old_place, new_place)
     values
       ('A1', 'B', 'D');
     
     insert into t2
       (id, old_place, new_place)
     values
       ('A2', 'C', 'E');
    
    insert into t2
       (id, old_place, new_place)
     values
       ('A4', '', 'k');
    My update statement
     update t yp
     set yp.place = (select jk.new_place  from t2 jk
     where jk.id = yp.id
     and jk.old_place = yp.place);
    so, basically, the logic behind the update statement is to update the place in the t table to a new location in the t2 table based on information obtained from table t2, where id and the former place of the t2 table correspond with the place in table t

    Published by: user13328581 on December 13, 2010 13:03

    Published by: user13328581 on December 14, 2010 07:58

    Published by: user13328581 on December 14, 2010 08:35

    Maybe

    update t yp
       set place = (select new_place
                      from t2
                     where id = yp.id
                       and nvl(old_place,'~') = nvl(yp.place,'~')
                   )
     where (id,nvl(place,'~')) in (select id,nvl(old_place,'~')
                                     from t2
                                  )
    

    Concerning

    Etbin

  • I Source name unique combination Autopost ID?

    I'm trying to run a validation by using the FND_REQUEST. PL/SQL SUBMIT_REQUEST API call
    After sucessfully import several combinations of SET_OF_BOOKS_ID and USER_JE_SOURCE_NAME;
    i.e.
    SET_OF_BOOKS_ID USER_JE_SOURCE_NAME
    --------------- -------------------
                  2 ARCHER_Fee R
                  2 Adjustment
                  2 BALANCE_Upload_R
    I would like to display specific to each combination and found that whenever I run a post (laid program for the GLPAUTOP), using the FND_REQUEST. SUBMIT_REQUEST procedure call, display more of a source occurs.

    The parameters of GLPAUTOP are SET_OF_BOOKS_ID & AUTOPOST_ID.
    I suspect that this is because the AUTOPOST_SET_ID is not unique, because when I run the following SQL:
      1  select  gpp.JE_Source_Name, gjs.User_JE_Source_Name, gpp.Autopost_Set_ID
      2  from    GL_Automatic_Posting_Options  gpp
      3         ,GL_Automatic_Posting_Sets     gps
      4         ,GL_JE_Sources                 gjs
      5  where   gpp.Autopost_Set_ID           = gps.Autopost_Set_ID
      6  and     gps.Set_Of_Books_ID           = 2
      7  and     gjs.JE_Source_Name            = gpp.JE_Source_Name
      8* and   gjs.User_JE_Source_Name in ('Adjustment','ARCHER_Fee R','BALANCE_Upload_R')
    SQL> /
    
    JE_SOURCE_NAME            USER_JE_SOURCE_NAME       AUTOPOST_SET_ID
    ------------------------- ------------------------- ---------------
    2                         ARCHER_Fee R                            2
    4                         Adjustment                              4
    75                        BALANCE_Upload_R                        2
    I noticed that the AUTOPOST_ID is not unique!
    Thus, for example, if I run the source 'ARCHER_Fee_R' display, display would occur for the "BALANCE_Upload_R" source as well. I would only the source "ARCHER_Fee_R" which will be shown however.

    If someone could advise as to what needs to be changed in order to get a unique combination of AUTOPOST_ID & SET_OF_BOOKS_ID for each specific "JE_SOURCE"?
    Or, Alternatively, how I can go about the recognition of a single source?

    New on Oracle Apps, so appreciate any help!

    THX

    P;

    Please set up an automatic recognition set criteria specifically to include the only categories you are interested in.
    Use the autopost_set_id of this configuration of automatic recognition criteria while submitting the process and which should
    filter sources categories is not necessary.

    Sets automatic recognition criteria are defined for combinations of the accounting plan and calendar. All of the access of data assigned to your responsibility determines the combination of the chart of accounts and the calendar that you set for all of your criteria.

    When you define a set of automatic recognition criteria, run the program of automatic recognition to select and display sheets that meet the criteria defined by the criteria. You can also schedule the program of recognition auto to run at specified times and intervals of the submission. You can submit the automatic recognition program or plan AutoPost series directly from the window series of automatic recognition criteria. Alternatively, you can use the window application.

    Hope this helps

  • I live in the United States and would like to buy a song from the Germany. Is this Possible?

    I live in the United States and would like to buy a song from the Germany. Is this possible?

    Hello

    You can buy songs that are available on iTunes Store for your country.

  • My browser is blocked for security reasons. Code error-QFR5000RT11C. My incoming connections in open State distance. Then I got the call from the United States 1 (866)986-3669, I picked up the phone, but they put the phone down. No matter what? Help, plea

    My browser is blocked for security reasons. Code error-QFR5000RT11C. My incoming connections in open State distance. Then I got the call from the United States 1 (866)986-3669, I picked up the phone, but they put the phone down. No matter what? Help, please.

    It's probably a SCAM.  Do not call these numbers.  Force Quit Safari and reopen it by holding down the SHIFT key.

    Ciao.

  • Unique problem with selction on the table (Query Page)

    Unique problem with selction on the table (Query Page)

    I have a VO data Bulletin Board, with a transitional attribute for selction unique column.
    My requirement is that I need to identify the line that was selected in the table.

    I associated with fireAction singleSelection column, such that whenever the user selects the line
    I'm looking for that VO using some rowIterator.
    But when running the loop of the transient VO that is mapped to the singleSelection variable is the show as "n" / NUll
    for all the lines...

    So how do you identify the selected line in singleSelection to a table.

    -Sasi

    In the property inspector of the element for which you've put firePartialAction, you can find a property named "parameters". That mention primary key as your setting.

    You can get the arameter using pageContext.getparameter ();

    -Anand

  • How to case statement based on the array of values of 3 or more?

    I'm trying to figure out how to do a comparison or case structure... based on the creation of an array of boolean 3 (or maybe more).

    I have a table (it's from a serial connection, and I am conversion back to a table to work with) [t, F, F] in this case I would like to display on a status indicator "STBY".

    If the array is defined on [F, T, F] I want to display in this indicator "ON".

    If the array is defined on [F, F, T] I want to display in this "EMPTY" indicator

    I can not understand how to compare combinations of things... I read in an array of bytes, and the first 3 bits in this example, determine what to display in a status... I can't figure out how to do with structure case... or without some channels to research and/or bad comparison...

    Any suggestions?

    Thanks in advance,

    Cayenne

    You can use search 1 d array and find the first real.

    Or you could convert the table of Boolean integer U8 and integer that results to determine which cases to run.  (4, vs, vs 1-2)

  • How to display a validation on a modal dialog error based on a unique constraint?

    Hi all

    Apex 4.1

    See example on apex.oracle.com:

    Workspace: EDIAZJORGE

    User name: TEST

    Password: test123

    Application: 55036 - Validation of modal Page

    I have a page with two elements, to make and model, where the user will be able to enter the model, say, a car and use a pick to dolist. If make does not exist, the user can click on the [+] button that opens a modal dialog box to add a new do.

    Everything works fine except when I try to insert a double do, which triggers a unique constraint violation error:

    AJAX call back Server error ORA-00001: unique constraint (EDIAZJORGE. MAKE_UK1) violated to execute the PL/SQL Code

    I want to enter this event and inform the user about an error inside the modal dialog box, but I don't know what is the best way to achieve this. My guess is that I'll have to make an Ajax call to run an application process and capture the exception of DUP_VAL_ON_INDEX, but I'm not very familiar with the Ajax part.

    Any suggestions?

    Thank you

    Erick

    I'm sorry Erick, I was in error. You always get an alert but with a nicer message. The actions of builtin DA do not allow interaction with them, so no way to manage the return of ourselves.

    In light of this, I copied the page in enforcement 77635 1-2 and made some changes to it. Basically, I copied the code to Jorge and modified so that it uses $.ajax instead of apex.server.process. I much prefer it to htmldb_Get - you shouldn't really use it either. More $.ajax has the advantage of this apex.server.process is based on it. That should work well on 4.1.

    Sorry Jorge, won't steal the Thunder, I guess I was... bored? And decided to do some apex?

  • All unique combinations of values in the same column of a group?

    Hi friends

    I have a table t with data as follows
    CREATE TABLE T
    (order_number number,
    item_name varchar2(3))
     
    INSERT INTO T VALUES (1,'A1');
    INSERT INTO T VALUES (1,'A2');
    INSERT INTO T VALUES (1,'B1');
    INSERT INTO T VALUES (1,'B2');
    INSERT INTO T VALUES (1,'C1');
    INSERT INTO T VALUES (1,'C2');
    INSERT INTO T VALUES (2,'A4');
    INSERT INTO T VALUES (2,'B1');
    INSERT INTO T VALUES (2,'A3');
    INSERT INTO T VALUES (2,'B5');
    INSERT INTO T VALUES (2,'C1');
    INSERT INTO T VALUES (2,'C2');
    
    sql> SELECT ITEM_NAME, ORDER_NUMBER FROM T
    /
    
    
    item name   order number
    A1             1
    A2             1
    B1             1
    B2             1
    C1             1
    C2             1
    ...
    ...
    A4             2
    B1             2
    A3             2
    B5             2
    C1             2
    C2             2
    
    In my table, each 'item' can appear just once in each 'order number'. 
    I want to join each item name to all other item names (without any repitition), within the same order number. 
    
    
    My desired output is like below:
    
    item name     item name   order number
    A1            A2          1
    A1            B1          1
    A1            B2          1
    A1            C1          1
    A1            C2          1
    A2            B1          1    
    A2            B2          1
    A2            C1          1
    A2            C2          1
    B1            B2          1    
    B1            C1          1
    B1            C2          1
    B2            C1          1
    B2            C2          1
    C1            C2          1    
    
    ......
    ......
    ......
    There are 15 combinations so the number 1
    .. .nCr where n = 6 and r = 2 NCR Yes = 15.


    Note: x A1 A2 is ignored because already, A1, A2 came in the first row of my desired output. similar cases for others combinations should be ignored as well.


    I want to have the shortest possible of a query with more rapid execution to achieve this goal. Because in my real table 2000 there order numbers and each order number has 10 unique objects.

    I look forward to the answer.

    concerning
    Hamza

    Published by: Hamza on July 10, 2011 22:55

    Published by: Hamza on July 10, 2011 22:58
    with t as (
               select 'A1' item_name,1 order_number from dual union all
               select 'A2',1 from dual union all
               select 'B1',1 from dual union all
               select 'B2',1 from dual union all
               select 'C1',1 from dual union all
               select 'C2',1 from dual
              )
    -- end of on-the-fly data sample
    select  t1.item_name,
            t2.item_name,
            t1.order_number
      from  t t1,
            t t2
      where t1.order_number = t2.order_number
        and t1.item_name < t2.item_name
      order by t1.order_number,
               t1.item_name,
               t2.item_name
    /
    
    ITEM_NAME  ITEM_NAME  ORDER_NUMBER
    ---------- ---------- ------------
    A1         A2                    1
    A1         B1                    1
    A1         B2                    1
    A1         C1                    1
    A1         C2                    1
    A2         B1                    1
    A2         B2                    1
    A2         C1                    1
    A2         C2                    1
    B1         B2                    1
    B1         C1                    1
    
    ITEM_NAME  ITEM_NAME  ORDER_NUMBER
    ---------- ---------- ------------
    B1         C2                    1
    B2         C1                    1
    B2         C2                    1
    C1         C2                    1
    
    15 rows selected.
    
    SQL> 
    

    SY.
    P.S. It your order_number big enough index table, nom_element would be useful.

  • Highlighting the lines of State based on the results of the report

    Hello! I think it's an easy question, but I have not found an answer for her through the forums looking. Is there a way to highlight or change the colors of some dependent lines on the result set data? I'm trying to display transaction data of the customer for call center agents and highlight some rows based on the values in the results...

    Thank you very much!

    You can view a customized report (column model) model - they give you 4 places for the conditions. Here is an example:

    Column Template 1: #COLUMN_VALUE#
    Column Template 1 Expression: '#1#' like '%Total%'
    

    #1 # being the first column in your results. This isn't bad if you only need 4 conditions and know the placement of your fields - you just configured different look and feels in your CSS and change the class according to the criteria.

    Here's another way:
    http://Apex.Oracle.com/pls/OTN/f?p=11933:7

    Hope that helps...

  • SELECT with the matter in that statement based on the procedure returning a Boolean

    Hi all

    I try to build a select statement with a case where the condition.
    SELECT COL_ID, COL_TITLE, COL_COMMENT,
               ( CASE WHEN COL_IT = :USER_ID THEN 'Y' 
                           WHEN COL_USER = :USER_ID THEN 'Y'
                           WHEN REGEXP_LIKE(COL_IT_ADD, '(^|:)(' || :USER_ID || ')(:|$)') THEN 'Y'
                           ELSE 'N' END ) MY_COL,
    FROM   MY_TABLE
    WHERE  ( CASE WHEN MY_PACKAGE.AUTHORIZE('IT') = TRUE THEN 'Y'
                           WHEN MY_PACKAGE.AUTHORIZE('IT') = FALSE AND COL_USER = :USER_ID THEN 'Y'
                           WHEN MY_PACKAGE.AUTHORIZE('IT') = TRUE AND  REGEXP_LIKE(COL_IT_ADD, '(^|:)(' || :USER_ID || ')(:|$)') THEN 'Y'
                           ELSE   'N' END ) = 'Y'
    The case for the calculation of the value of the column works fine. Run this query without the where also works in condition.
    But in the condition, I get the following error: SQL error: ORA-00920: invalid relational operator 00920. 00000 - "invalid relational operator.
    The MY_PACKAGE procedure. AUTHORIZED (pValue) returns a Boolean value. Is it possible to use a case statement in the WHERE condition to calculate a value and check for this? If not, is there another way to do something like this in a query?

    Thanks for your help
    Chrissy

    The Boolean data type is unknown in SQL... you cannot use functions that return Boolean values in SQL.

    You can add a function overloaded in the package which returns a 'Y' or a 1, or something else that is a data type in SQL.

Maybe you are looking for