How to select the record in the mulitple rows based on values in another field?

Hello

Sorry for the bad title, really don't know how to explain it

Have the following data:
 
Cost_center       Activity_type
1005009401     CLBR0
1005009401     CLBR1
1005009401     TLBR0
1005009401     TLBR1
1005009401     VEH00

1005009402     CLBR3
1005009402     CLBR4
1005009402     TLBR5
1005009402     TLBR6
1005009402     VEH07

1005009901     CE000
1005009901     CLBR0
1005009901     CLBR1
1005009901     TLBR0
1005009901     TLBR1
1005009901     VEH01
I need to return a list of cost (with its associated activity types) centers have no activity types of CLBR0 and CLBR1 and TLBR0 and TLBR1 and VEH01. So in the above data, cost center, 1005009401, and 1005009402 will be returned.

Any thoughts?

Thank you.

Published by: dgouin on August 29, 2012 11:42 - added several examples of data.

Published by: dgouin on August 29, 2012 11:45

Published by: dgouin on August 29, 2012 11:49

Sorta kludgey, but functional:

WITH ccs AS
  (
  SELECT '1005009401' AS CC, 'CLBR0' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009401' AS CC, 'CLBR1' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009401' AS CC, 'TLBR0' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009401' AS CC, 'TLBR1' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009401' AS CC, 'VEH00' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009901' AS CC, 'CE000' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009901' AS CC, 'CLBR0' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009901' AS CC, 'CLBR1' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009901' AS CC, 'TLBR0' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009901' AS CC, 'TLBR1' AS activity_type FROM dual
  UNION ALL
  SELECT '1005009901' AS CC, 'VEH01' AS activity_type FROM dual
  )
SELECT cc, activity_type
FROM   ccs c1
WHERE  5 != (SELECT COUNT(DISTINCT activity_type)
             FROM   ccs c2
             WHERE  activity_type IN ('CLBR0','CLBR1','TLBR0','TLBR1','VEH01')
             AND    c1.cc = c2.cc
            );

CC         ACTIVITY_TYPE
---------- -------------
1005009401 CLBR0
1005009401 CLBR1
1005009401 TLBR0
1005009401 TLBR1
1005009401 VEH00  

Tags: Database

Similar Questions

  • How can I delete records of a 3D table based on values in a field?

    In the attached table 3D I want to delete all the records that have no 3A 900000 / 3 has 900001/or 3A 900002 in field 2. Is there an easy way to do this?

    Thank you.

    Instead of delete why didn't you find and replace rather--much more effective anyway due to no resizing of the table.  Consider this in your subsequent treatment table.

  • How to select the second row in three?

    I use answers and are in a situation where some IDs have three related lines.

    I'm trying to flatten it so that each of these lines is displayed as a column.

    So instead of:

    ID fruits

    1 Apple

    2 Orange

    Peach 2

    2 plum

    Mango 3

    I want to see

    1 Apple

    2 plum fishing orange

    Mango 3

    I can get to the first (orange) and the last (plum) with MIN and MAX.

    For example (fruit) MIN or MAX (fruit)

    Answers how select the line in the middle (fishing)?

    Thank you!

    Use LISTAGG, but then to analyze the first second and third in their own columns using regular expressions... or change the data structure to match the use of the information (use is the master, not the slave)

  • Select the duplicate rows, based on a combination of columns as the key

    Hello

    I have a table with 5 columns.

    Code ID S_DATE E_DATE name
    1 23 01012001 null ABC
    1 09 01012001 null XYZ
    2 81 04022007 null TVU
    1 43 03092008 null XXX



    Now, I need to write a select statement to extract the lines duplicated in the table above with the combination of (Code, S_DATE, E_DATE) as the key.
    So in the above example, I need to get Row1 and Row2 as output (but not Row3 as she has a different S_DATE)

    Thanks in advance for your suggestions.

    Thank you

    Published by: thotaramesh on March 9, 2009 16:54

    The XE;

    WITH sample_data AS (
       SELECT 1  code,23 ID, '01012001' s_date, null e_date, 'ABC' NAME FROM dual UNION ALL
       SELECT 1, 09, '01012001', null, 'XYZ' FROM dual UNION ALL
       SELECT 2, 81, '04022007', null, 'TVU' FROM dual UNION ALL
       SELECT 1, 43, '03092008', null, 'XXX' FROM dual)
    SELECT code, ID, s_date, e_date, NAME
    FROM (
       SELECT
          sample_data.*,
          COUNT(*) over (PARTITION BY code, s_date, e_date) dups
       FROM sample_data)
    WHERE dups > 1;
    
          CODE         ID S_DATE   E_DATE NAME
    ---------- ---------- -------- ------ ----
             1         23 01012001        ABC
             1          9 01012001        XYZ
    
  • How to use the Type of Oracle Table values in the Select statement.

    Hello

    I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.

    For example, try something like the following:

    TYPE t_record () IS RENDERING
    ID TABLEA.ID%type,
    NO TABLEA.NO%type

    );
    v_record t_record;
    T_table TYPE IS the v_record TABLE % TYPE;
    v_table t_table;

    -Code to fill the values of v_table here.

    SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
    WHERE ID IN (i) v_table USER.USER;

    I want to know how to use the Type of Oracle Table values in the Select statement.

    Something like this:

    create or replace type t_record as  object (
    id number,
    no number
    )
    /
    
    CREATE or replace type t_table AS TABLE OF t_record;
    /
    
    set serveroutput on
    declare
    
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    
    begin
    
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
    
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
    
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
    
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /
    

    No test!

    P;

    Published by: bluefrog on March 5, 2010 17:08

  • Printer all in one HP3520 - how to select the wireless network and enter the WEP key?

    According to print my wireless network is detected.

    How to connect the! @# % printer $ fo the wireless network and enter the WEP key?

    Instructions on the HP site tell me to selet NETWORK on the printer control panel.  Well, there's a way to select the NETWORK from the control panel.  It is not an option for him.

    I downnloaded and installed the latest drivers.

    I have restored the default settings.

    How to select the wireless network and enter the WEP key?

    All of HP's instructions seem to be for a newer printer with a touchscreen.

    I want that the printer is connected to my main computer via the USB port.  I want to be able to print wireless phones and tablets.

    My 3520 is not a 'touch Screen' and it has wifi.

    However, the following work:

    Try to open the HP Deskjet 3520 icon, open the utilities tab, click on convert USB wireless, by following the steps on the screen.

    This leads me to believe that ONLY the wireless doesn't work.  I know now that the part of the sentence "Convert USB to wireless connection" is supposed to mean "works like USB and wireless.

    Thank you for your help

  • How to select the pieces of my image in black and white?

    How to select the pieces of my image in black and white? FOW example letter J or the circle or the two together?

    jaguar_growler_blur best8.png

    It's actually pretty easy, but I have to assume that you know a few basics in Photoshop

    (1) open your existing image

    (2) double click on the layer and the 'layer style' appears. In the mix if area set the sliders so the whites in the image disappears

    You will be left with just the black elements in design

    (3) duplicate layers

    and merge them together

    to give a standard layer

    (4) ctrl or cmd click on the layer to select and create a layer mask

    (5) you now have a mask of the image. Duplicate the layer, click alt or option, click on the layer mask to call

    (6) the blacks and the whites are not completely black and white for the use of levels to adapt to the absolutes

    (7) now you have to decide what you want to select. In this case, I chose the lettering and simply covered everything else to the top with black. You do this by lasso selection and fill and items when it's delicate brush just the details with a black brush "hard." .

    (8) at this stage, you can do what you want you have a layer mask. So you can color the text for example

    or place in a background color and apply a layer as Beveling effect

    Hope that makes some sense. It is much easier to do than to describe.

  • How to select the Type of industry 8.3 Professional P6

    Hi all

    According to the document to change the type of industry for 8.3 Professional P6, I had to go to P6, Application settings, general link.

    But in the P6 Web client to administrator > Application Configuration > General there is no option is available for the type of industry.

    Let me know, how to select the type of industry?

    You can see the OPINION score "How to change the Type of industry P6 P6 PPM (Professional), P6 EPPM E8.2 and later versions (Doc ID 1386047.1)".

    Also can you paste a screenshot here.

  • How to select the path to a file icon button to a table?

    I have a SYSTEM_PATHS table name. All physical access paths as 'where the forms of execution are located' or 'where performance reports are located' are stored in its ranks for example (C:\HRMS\FORMS\)
    I memorized the path of the icon files (.ico) inside. The forms of execution can take the path of the icons for the buttons of this table. And access the icon of the chosen path. I use forms 6i. Normally, I put the path of the icon files in the nerve to property of the button as (C:\HRMS\ICON\). But now, here, I don't have a path but its in the column of a table. How to select the path to a file icon button to a table using forms 6i?

    Hello Gul,

    have you tried

    set_item_property('Button name',ICON_FILENAME,);
    

    Concerning
    Marcus

  • How to select the same forms of color in the adobe flash program?

    How to select the same forms of color in the adobe flash program? for example, we assume that 10 forms of rectangle. 3 of them are red and others are green. I want to use only one method or click to select 3 of them. Please help me

    Thanks kunter

    You can use Ctrl + F.

  • How to extend the display fron Windows 8.1 to another laptop Windows 7

    How to extend the display fron Windows 8.1 to another laptop with Windows 7, without having to invest in additional software.

    Hello Navin,

    Thank you for visiting Microsoft Community.

    According to the description, I understand that you want to know how to extend Windows 8.1 display to another laptop with Windows 7.

    Certainly, I understand your concern and will try my best to help you.

    I want to provide you with the information that so there is no solution from Microsoft to do this. However, there are third-party software that could help you extend the display from one computer to the other. But Microsoft does not recommend that.

    Note: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    I hope this information is useful.

    Please let us know if you need more help, we will be happy to help you.

    Thank you.

  • How to move the virtual machine from one cluster to another cluster

    How to move the virtual machine from one cluster to another cluster

    If two Clusters are in the same data center, you could do a 'live' migration or vMotion, if that's the case.   If the virtual machine is turned off, it may be migrated regardless of the data center.

  • How do I delete an article based on the value of another field


    I have a pdf form that I added to the text fields. My challenge is that of the financial section of the form, if the value of a specific field is empty or null, I blank block of signature financial review.  I've been trying to find a way to cover the area of signature with a white box or have a text box with signature block text appear or disappear depending on whether the value is zero or empty.

    If seen many answers on how to make the field itself disappear based on value, but I did find something that causes another field or shape appear or disappear depending on the value of another field.

    Please try the following script,

    var signid = true;

    If (this.getField("finan").value! = 0) signid = true;

    of another signid = false;

    If (SignID) this.getField("signaturefield").display = display.visible;

    else this.getField("signaturefield").display = display.hidden;

    Please let me know if it solves the problem.

  • By selecting the last row of the table

    I'm trying to select the last row in a table. The tables will have a different number of lines, so I can't select based on a line number. I tried to use the location options, but get an error that "the object is not a function". Not sure what the problem is.

    table = app.selection[0];
    if (table.hasOwnProperty("baseline")) table = table.parent;
    if (table instanceof Cell) table = table.parent;
    if (table instanceof Column) table = table.parent;
    if (table instanceof Row) table = table.parent;
    if (table instanceof Table)
    
    {
                table.rows(LocationOptions.AT_END).cells.texts.everyItem().fontStyle = "regular";
     }
    

    You can use the placement options for this?

    Hello

    table. Rows being a collection of object using the index-[1] is a proper way

    but cells.texts generates an error. Change it to:

    table.rows[-1].cells.everyItem().texts.everyItem().appliedCharacterStyle = "myriad regular";
    

    Jarek

  • Fill a field value based on the value of another field

    Hello
    Could someone tell me what is the problem with the following select statement. For a group of records, trying to fill a field with a value based on the value in another field (problem of status), but the Group of records appears empty just when I put this code in the field.
    Any help would be appreciated
    Thank you


    <? choose:? >
    <? When: IssueStatus = "Open"? >
    <? 1? >
    <? end when? >
    <? otherwise:? >
    <? When: IssueStatus = "closed"? >
    <? 2? >
    <? end when? >
    <? otherwise:? >
    <? When: IssueStatus = "Unresolveable? >
    <? 3? >
    <? end when? >
    <? end otherwise? >
    <? end to choose? >

    Use the following syntax.

    
    
    Display 1
    
    
    Display 2
    
    
    Display 3
    
    
    

Maybe you are looking for