mark the first value of a group

I get the following
16:57:28 >r
  1  with my_table as
  2       (
  3      select 'M082012' pera, to_number(10584338) snr, to_number(10) pnr, 'Beule' name, 'Anna' f_name from dual union all
  4      select 'M092012' pera, to_number(15965177) snr, to_number(15) pnr, 'Tester' name, 'Toni' f_name from dual union all
  5      select 'M082012' pera, to_number(14254501) snr, to_number(20) pnr, 'Wallen' name, 'Monika' f_name from dual union all
  6      select 'M082012' pera, to_number(10584339) snr, to_number(10) pnr, 'Beule' name, 'Anna' f_name from dual union all
  7      select 'M092012' pera, to_number(15965178) snr, to_number(10) pnr, 'Beule' name, 'Anna' f_name from dual union all
  8      select 'M012013' pera, to_number(10674833) snr, to_number(15) pnr, 'Tester' name, 'Toni' f_name from dual union all
  9      select 'M012013' pera, to_number(10674834) snr, to_number(15) pnr, 'Tester' name, 'Toni' f_name from dual union all
 10      select 'M012013' pera, to_number(10539210) snr, to_number(30) pnr, 'Klose' name, 'Werner' f_name from dual union all
 11      select 'M012013' pera, to_number(12345678) snr, to_number(50) pnr, 'Meier' name, 'Otto' f_name from dual union all
 12      select 'M012013' pera, to_number(22345789) snr, to_number(50) pnr, 'Meier' name, 'Otto' f_name from dual union all
 13      select 'M082012' pera, to_number(10584346) snr, to_number(77) pnr, 'Carl' name, 'Frank' f_name from dual union all
 14      select 'M062012' pera, to_number(10550971) snr, to_number(77) pnr, 'Carl' name, 'Frank' f_name from dual union all
 15      select 'M092012' pera, to_number(15965185) snr, to_number(77) pnr, 'Carl' name, 'Frank' f_name from dual union all
 16      select 'M082012' pera, to_number(10584352) snr, to_number(50) pnr, 'Meier' name, 'Otto' f_name from dual union all
 17      select 'M092012' pera, to_number(15965191) snr, to_number(80) pnr, 'Duster' name, 'Hucke' f_name from dual)
 18  select case when pera = 'M012013' then '*' end mark,
 19         pera, snr, pnr, name, f_name
 20  from (
 21        select pera, snr, pnr, name, f_name,
 22               max(case when pera = 'M012013' then 'Y' end)
 23                 over(partition by upper(name||f_name)) m_flag,
 24               count(*) over(partition by upper(name||f_name)) cnt
 25        from my_table
 26       )
 27  where m_flag = 'Y'
 28  and cnt > 1
 29* order by 4,5,6, to_number(substr(pera,4,4)||substr(pera,2,2)) desc

MARK  PERA           SNR        PNR NAME   F_NAME
----- ------- ---------- ---------- ------ ------
*     M012013   10674834         15 Tester Toni
*     M012013   10674833         15 Tester Toni
      M092012   15965177         15 Tester Toni
*     M012013   22345789         50 Meier  Otto
*     M012013   12345678         50 Meier  Otto
      M082012   10584352         50 Meier  Otto
I would like to mark only the first value in the group with an asterisk as follows.
MARK  PERA           SNR        PNR NAME   F_NAME
----- ------- ---------- ---------- ------ ------
*     M012013   10674834         15 Tester Toni
      M012013   10674833         15 Tester Toni
      M092012   15965177         15 Tester Toni
*     M012013   22345789         50 Meier  Otto
      M012013   12345678         50 Meier  Otto
      M082012   10584352         50 Meier  Otto

Perhaps this example might be useful for you. the code uses the same code that you published with additional analytical query to return the row grouping for the name, the NRP and columns pera. then use that line number to determine which will be placed at the first mark.

SQL>   with my_table as
  2         (
  3        select 'M082012' pera, to_number(10584338) snr, to_number(10) pnr, 'Beule' name, 'Anna' f_name from dual union all
  4        select 'M092012' pera, to_number(15965177) snr, to_number(15) pnr, 'Tester' name, 'Toni' f_name from dual union all
  5        select 'M082012' pera, to_number(14254501) snr, to_number(20) pnr, 'Wallen' name, 'Monika' f_name from dual union all
  6        select 'M082012' pera, to_number(10584339) snr, to_number(10) pnr, 'Beule' name, 'Anna' f_name from dual union all
  7        select 'M092012' pera, to_number(15965178) snr, to_number(10) pnr, 'Beule' name, 'Anna' f_name from dual union all
  8        select 'M012013' pera, to_number(10674833) snr, to_number(15) pnr, 'Tester' name, 'Toni' f_name from dual union all
  9        select 'M012013' pera, to_number(10674834) snr, to_number(15) pnr, 'Tester' name, 'Toni' f_name from dual union all
 10        select 'M012013' pera, to_number(10539210) snr, to_number(30) pnr, 'Klose' name, 'Werner' f_name from dual union all
 11        select 'M012013' pera, to_number(12345678) snr, to_number(50) pnr, 'Meier' name, 'Otto' f_name from dual union all
 12        select 'M012013' pera, to_number(22345789) snr, to_number(50) pnr, 'Meier' name, 'Otto' f_name from dual union all
 13        select 'M082012' pera, to_number(10584346) snr, to_number(77) pnr, 'Carl' name, 'Frank' f_name from dual union all
 14        select 'M062012' pera, to_number(10550971) snr, to_number(77) pnr, 'Carl' name, 'Frank' f_name from dual union all
 15        select 'M092012' pera, to_number(15965185) snr, to_number(77) pnr, 'Carl' name, 'Frank' f_name from dual union all
 16        select 'M082012' pera, to_number(10584352) snr, to_number(50) pnr, 'Meier' name, 'Otto' f_name from dual union all
 17        select 'M092012' pera, to_number(15965191) snr, to_number(80) pnr, 'Duster' name, 'Hucke' f_name from dual)
 18    select case when pera = 'M012013' and rn = 1 then '*' end mark,
 19           pera,
 20           snr,
 21           pnr,
 22           name,
 23           f_name
 24      from (select pera, snr, pnr, name, f_name,
 25                   row_number() over (partition by pera, pnr, name, f_name order by pera, pnr, name) rn
 26              from (select pera, snr, pnr, name, f_name,
 27                           max(case when pera = 'M012013' then 'Y' end)
 28                           over(partition by upper(name||f_name)) m_flag,
 29                           count(*) over(partition by upper(name||f_name)) cnt
 30                      from my_table)
 31                     where m_flag = 'Y'
 32                       and cnt > 1
 33             order by 4,5,6, to_number(substr(pera,4,4)||substr(pera,2,2)) desc)
 34    order by 4,5,6, to_number(substr(pera,4,4)||substr(pera,2,2)) desc;

MARK PERA           SNR        PNR NAME   F_NAME
---- ------- ---------- ---------- ------ ------
*    M012013   10674834         15 Tester Toni
     M012013   10674833         15 Tester Toni
     M092012   15965177         15 Tester Toni
*    M012013   22345789         50 Meier  Otto
     M012013   12345678         50 Meier  Otto
     M082012   10584352         50 Meier  Otto

6 rows selected

SQL> 

Tags: Database

Similar Questions

  • I have a column with two values, separated by a space, in each line. How to create 2 new columns with the first value in a column, and the second value in another column?

    I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?

    Add two new columns after than the original with space separated values column.

    Select cell B1 and type (or copy and paste it here) the formula:

    = IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    shortcut for this is:

    B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")

    or

    the formula of the C1 could also be:

    = IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")

    Select cells B1 and C1, copy

    Select cells B1 at the end of the C column, paste

  • values based on the following logic 'values after the first values of two '_' and before last '_' values '.

    Hi all

    I need the values according to below 2logics in a single select query using instring and substring

    1 values based on the following logic 'values after the first values of two '_' and before last '_' values '.

    2 values based on the following logic 'values after the first values of two '_' and before last'-'values '.

    EXM:

    Entry: ABCD_EFGH_IJKLM - NOPQ_XYZ output: IJKLM - NOPQ

    Entry:. ABCD_EFGH_IJKLM - NOPQ output:IJKLM

    Thank you.

    Check the following

    WITH DATA1 AS

    (SELECT "ABCD_EFGH_IJKLM - NOPQ_XYZ" double val)

    UNION ALL

    SELECT 'ABCD_EFGH_IJKLM - NOPQ' double val

    )

    SELECT SUBSTR (VAL, INSTR(VAL,'_',1,2) + 1, DECODE (BIGGER (INSTR (VAL, '_',-1, 1), INSTR(VAL,'-',-1,1)), INSTR (VAL,'-', - 1, 1), LENGTH (VAL) + 1, INSTR (VAL, '_',-1, 1))-(INSTR (VAL, '_', 1, 2) + 1))

    OF DATA1;

    Concerning

    Salim

  • selectOneChoice displays the first value of the attribute

    Hi people,

    In my demo application, there are a couple of selectOneChoice drop down LOV which are based on the query based VO. The UnselectedLabel property is set to "No Selection". These LOVs are used to filter the set of query data. When the drop down menus are not called and the push of a button, the LOVs, behind the stage, have the first value of the attribute that is assigned automatically. Is there a way to ciircumvent the issue without the implementation of valueChangeEventListener?

    Thank you

    udys

    udys,

    It's not like you have implemented correctly.

    1. the error message says:

    "The class"oracle.summit.selfservice.view.HZHRLocsocBean"does not have the property"vLocvalue"

    On the screenshot, it is clear that the name of the variable is "fromLovValue" and not "vLocvalue". Please make sure you use the correct name.

    Reference:

    Advice from the Oracle Johny: ADF: how to create SelectOneChoice based on values from a database table in the ADF Web Application

    See you soon

    AJ

  • Select list failed at the first value

    APEX Version: 4.1.1.00.23

    Oracle database: 11g


    Question: The application updates the value selected in the list of selection (O/N) to the database, but at the front end, the selection list is set by default to display only the first value in the list. I think this is the data type of the field in the table attached to this select list is TANK (2). And change to VARCHAR2 (2), it worked fine. Now whichever option I choose in the selection list is updated and displayed on the front as well.


    I do not understand why is this to mess with (2) TANK. Someone at - it explain it please, I'd appreciate it really.


    Thank you

    Chrystelle

    never use CHAR() in your tables.

    TANK always touch your strings to the exact same length.

    In your case, you compare the value to the value of the list of the 'Y' table 'Y '.

    declare

    a tank (2): = 'Y ';

    b varchar2 (2): = 'Y ';

    Start

    dbms_output.put_line ('element A as a sign of ' | length (a)); -This will ALWAYS have a length of 2

    dbms_output.put_line ('Variable A as a sign of ' | length (b));

    end;

  • Drop-down list always displays the first value? How can I empty place

    I have several drop down from the fields list. An example would be the city. It allows a user to select a city. I want the form to be completely empty to start. Currently, when the form is initially pulled up, it shows the first value in the list. All my drop-down list fields exhibit the same behavior. Is it possible to be just empty instead?

    You can send the form to [email protected] and I'll take a look to see what is happening?

    Thank you

    Paul

  • Select the first value in the list of values when running in poplist

    Hello
    IM using forms 6i. I filled the poplist by request. But what I need, I want to choose the first value in the list of values when running...

    That is to say, during execution, the poplist should have chosen its first value in the list of values.

    What to do...

    Concerning
    Sery

    WHEN CREATING a RECORD of the block of the list item or after the filling of the list item, you can write

    : my_list_item: = GET_GROUP_CHAR_CELL ('my_list_item', 1); / * If the data type of the item in your list is character.*.

    Here, instead of 1, you can give any clue... 1: value to the first list item position

  • Set the first value after the select statement

    Hello

    I have a problem here.

    After you run the statement select, it'll come to me:

    COM
    DLY
    EXC
    NRD
    RDY



    My question: How can I set the first value instead of 'COM' in "EXC"?

    Thank you.

    Hello
    Where you use this instead:

    select *
    from
    (
    select col_name
    ,case when col_name='EXC' then 1 else 0 end as "id"
    from table_name
    )
    order by "id" desc
    
  • Fill area of the screen with the first value in the record group

    Hi guys, what the title essentially says. I have a display element that is populated by the by selecting the appropriate option in a LOV. Is there a method that I can put in when a new instance of the form or something else to fill the screen with the first item in the record group used to fill the lov to ensure when the load form display area is not empty. I know I have to hard just in code, but I would have the value come from the record group.


    Thank you

    Published by: user13390506 on August 25, 2010 05:39

    This works very well for me:

    Created a record group (RG1) with the following order of selection:

    select table_name, table_name from user_tables order by 1
    

    Created a button on the Web that are running the following:

    PROCEDURE pop IS
       rg_id RecordGroup;
       gc_id GroupColumn;
       col_val VARCHAR2(1000);
       n number ;
    BEGIN
    
       rg_id := Find_Group( 'rg1' ); 
    
       IF Id_Null(rg_id) THEN
       Message('Record Group rg1 does not exist.');
       RAISE form_trigger_failure;
       END IF; 
    
       n := Populate_Group( rg_id) ;
       gc_id := Find_Column( 'RG1.TABLE_NAME' ); 
    
       IF Not Id_Null(gc_id) THEN
         col_val := GET_GROUP_CHAR_CELL( gc_id, 1 );
         message(col_val);
       End if ;
    
    End;
    

    I guess the record_name.column_name at the top of case...

    François

  • Display the first value in a list after sorting

    Hello

    I'm trying to display a single value in a field in a list of values I want to sort in descending order.
    I tried the following code, but it gives me the first record in the list before sorting.
    How can I get the first record in the list after the sorting?

    <? for each: StatusHistory [position () = '1' and the role = "study Manager"]? > <? sort: created; ' descending '; type_donnees = "text"? > <? choose:? > <? When: created! ='' ? > <? xdofx:substr(created,12,2)? >: <? xdofx:substr(created,15,2)? >: <? xdofx:substr(created,18,2)? > <? end when? > <? otherwise:? > <? end otherwise? > <? end to choose? > <? end for each? >

    Thank you

    Try this:



    your online data

    See you soon

    Jorge
    p.s if this answers your question please grant points, and then close the message

  • I'm trying to access the selected value of a group of radiobutton Error #1006

    I'm trying to access the selected value of a radiobutton group, but when I do it like this:

    Debug.Text = radiogroup1.selectedValue (m:System.NET.SocketAddress.ToString ());

    I get an error like actionscript:

    TypeError: Error #1006: value is not a function.
    hand / debug1 () [Z:\mysite.co.uk\Staff\src\main.mxml:47]
    hand / ___main_Button2_click ([Z:\mysite.co.uk\Staff\src\main.mxml:372])

    No help from friendly people? ;-)

    Debug.Text = radiogroup1.selectedValue.toString ();

  • How I can add to a table of defined length and have the first value is the first value out.

    I want to build/adding a table. Let's say that the length is set to 10 items. When is element 11 I want the first element to be expelled for that table a always the latest 10 items in there in order. the berries should look like this:

    {0,1,2,3,4,5,6,7,8,9}

    1,2,3,4,5,6,7,8,9,10 {}

    {2,3,4,5,6,7,8,9,10,11}

    etc.

    Any help is greatly appreciated. Thank you

    Here's a VI revised, except that I use LV8.5 and the lowest, I can record down to is 8, so maybe someone will be kind enough to convert it?

    Attached an image too

  • function in pipeline does not return the first values of immediately?

    I'm new to features in the pipeline. I want to get the first results of this function in the pipeline as soon as possible. But in my test case, I get all the lines at the end, when the function ends.

    create or replace
    dummy function
    return DBMS_DEBUG_VC2COLL
    PIPELINED - NOTE the keyword in pipeline
    is
    Start
    line of conduct (to_char (sysdate, ' DD-MON-YYYY HH24:MI:SS'));))
    DBMS_LOCK. Sleep (90);
    line of conduct (to_char (sysdate, ' DD-MON-YYYY HH24:MI:SS'));))
    return;
    end;
    +/+

    I expect
    + January 20, 2009 08:32:51 + immediately
    a 90-second delay
    + 08:34:21 + 20 January 2009 thereafter.

    But I have two lines after 90 sec.

    Can I change the behavior of this function somehow, or is this the only default behavior and I have to find other solutions?

    Thanks in advance
    Martin

    A parameter in your SQL * Plus has an influence on behavior, specifically the ArraySize.

    by your function (pipe_nums), run this:

    select * from table(pipe_nums);
    
    set arrays 5
    
    select * from table(pipe_nums);
    

    and notice the difference

  • How to display the first value in the line in the second row and the second value of the line on the third row and so on...

    Hi all

    I have a requirement as below.

    Select * from my_tab;

    col1 col2 col3

    1 test1 January 1, 2014

    Test2 2 2 January 2013

    3 test5 February 9, 2015

    I need to display it as below.

    col1 col2 col3 req_col

    -----------------------------------------------------

    1 test1 January 1, 2014

    2 test2 January 2, 2013 January 1, 2014

    3 February 9, 2015 test5 January 2, 2013

    So how do?

    If it is not possible with sql then suggest me to do in peblisher xml (in rdf or rtf)

    Hello

    jagadekara wrote:

    Hi all

    I have a requirement as below.

    Select * from my_tab;

    col1 col2 col3

    1 test1 January 1, 2014

    Test2 2 2 January 2013

    3 test5 February 9, 2015

    I need to display it as below.

    col1 col2 col3 req_col

    -----------------------------------------------------

    1 test1 January 1, 2014

    2 test2 January 2, 2013 January 1, 2014

    3 February 9, 2015 test5 January 2, 2013

    So how do?

    If it is not possible with sql then suggest me to do in peblisher xml (in rdf or rtf)

    In SQL, you can use the analytic LAG function.

    http://docs.Oracle.com/database/121/SQLRF/functions093.htm#sthref1544

    Because I don't have a copy of your table, I'll use scott.dept to illustrate:

    SELECT DeptNo

    dname

    loc

    , Trolling (loc) over (ORDER BY deptno) AS prev_loc

    OF scott.dept

    ORDER BY deptno

    ;

    Output:

    DEPTNO DNAME LOC PREV_LOC

    ---------- -------------- ------------- -------------

    10 ACCOUNTS NEW YORK

    SEARCH 20 DALLAS NEW YORK

    30 SALES CHICAGO DALLAS

    40 OPERATIONS BOSTON CHICAGO

  • First column display and all others with contains the first value

    Hello

    I have to query the table and display the result in such a manner:

    Batch value1
    value2
    value3
    value11 status_id2
    value13
    value18

    and so on... Could someone help me how to do this?

    Dear tutus!

    Is that what you want to do?

    break on a
    SELECT c.a, c.b, d.counter
    FROM   test c, (SELECT a, b, COUNT(b) OVER (PARTITION BY a ORDER BY a) AS counter
                    FROM   test) d
    WHERE  c.a = d.a
      AND  c.b = d.b
      AND  counter > 1
    

    Yours sincerely

    Florian W.

Maybe you are looking for

  • Why can I only run firefox as administrator - associated with zonealarm

    This has happened frequently usually after an upgrade, it is causing security problems I have now a virus that took advantage of this situation. This seems to be a consistent failure through the lifecycle of firefox, I will not work as an administrat

  • I can't open the images in Yahoo mail with 7 Firefox, but IE works.

    After several years of success with Yahoo mail and Firefox, I can longer open mail of Yahoo (jpg, bmp) images. I can open them in gmail with Firefox or IE. I can open them in Yahoo mail using IE. I am running Firefox 7.0.1 and I think, but am not sur

  • Pavilion my audio beats

    Today, I noticed that my audio beats is no longer on my Pavilion m7-1015dx. I have upgraded to windows 8.1 a few months ago, and by updating the system to the latest drivers, I see more audio beats. I have updated the latest IDT and BIOS as well as o

  • Windows live Error 0x800ccc0d mail after security update

    Can't send or receive messages on behalf of the Vertical. The host 'mail.xxx.com' is not found. Please check that you have entered the server name correctly. Server: 'mail.xxx.com '.Windows Live Mail error ID: 0x800CCC0DProtocol: POP3Port: 110Secure

  • Get nlssrv32.exe is not recent version when opening Nitro pro 8

    original title: nlssrv32.exe is not the current version I installed Nitro pro 8 but has found an error: "nlssrv32.exe is not the current version. I have this file installed in SysWow64, and my OS is W7 64-bit. How can I solve the problem? Thank you t