Get second-highest element in hierarchy

It's Friday afternoon and my brain isn't working well, and some of you people I'm sure will have the answer in a flash....
I have a typical hierarchical table, here's an example below;
with codes as
(select 17 icode,     -1 parent_code,'Group Services' descrip from dual
UNION
select 18,     -1,     'Counselling' from dual
UNION
select 20,     -1,     'Career Decision Making' from dual
UNION
select 21,     20,     'Career Assessment' from dual
UNION
select 22,     20,     'Academic Assessment' from dual
UNION
select 27,     22,     'Fee' from dual
UNION
select 28,     22,     'Transportation' from dual
UNION
select 33,     28,     'In-Province' from dual
UNION
select 34,     21,     'Fee' from dual
UNION
select 35,     21,     'Transportation' from dual
UNION
select 39,     35,     'Daily' from dual),
intervs as
(select 17 interv from dual
union select 18 interv from dual
union select 27 interv from dual
union select 33 interv from dual
union select 34 interv from dual
union select 39 interv from dual)
select interv,x.*
from intervs
INNER JOIN (select l1.icode k1,l1.descrip d1,
l2.icode k2 ,l2.descrip d2,
l3.icode k3 ,l3.descrip d3,
l4.icode k4,l4.descrip d4
from codes l4
left outer join codes l3 ON l3.icode = l4.parent_code
left outer join codes l2 ON l2.icode = l3.parent_code
left outer join codes l1 ON l1.icode = l2.parent_code)
x ON x.k4 = intervs.interv
What I would like to get for each intervs.interv is the k/d pair that is the second highest element in the hierarchy, or if there is no higher level in the hierarchy I'll take that.
So in the data that the above displays, I'd like 22 - academic assessment for #33,
21 Career Assessment for #34, and 18 and 17 would come back as themselves.
Thanks in advance,
Jon

or you can use the tradtional sql, it can run in most database
select * from scott.emp t11,
--get the second highest sal
select deptno, max(sal) sal
from
( --get the highest sal
select t1.deptno, t1.empno, t1.ename, t1.sal from scott.emp t1,
( select deptno,max(sal) max_sal
from scott.emp e
group by deptno
) t2
where t1.deptno=t2.deptno
and t1.sal<t2.max_sal
order by t1.deptno asc,sal desc
) t
group by t.deptno
order by t.deptno
) t22
where t11.deptno=t22.deptno
and t11.sal=t22.sal;

Similar Messages

  • Getting 'second reporting supervisor' without hierarchy

    Hi all
    Just I hope that someone can help me with this... Just describing it it feels complicated, but here we go.
    An Employee table contains information about Employees and their Bosses
    EmpID, BossID
    emp01, emp02
    emp02, emp03
    I want to create a report displaying the Supervisor and the 'Second reporting supervisor; i.e. the boss's boss, like:
    Employee, Boss, 2nd Boss
    emp01,emp02,emp03
    Any advice? Points awarded!

    Basically you need to create the denormalised structure in the physical model using aliaseses on the base table, and join accordingly.
    Dim_Emp >--- Dim_Emp_Boss >---- dim_Emp_boss_boss
    This assumes you know the number of levels in your structure.
    The alternative is to do some transformation of your table into a HIER_DN table which gives all the levels.

  • How to get multiple measures in measure hierarchy in Essbase Studio

    Hi All,
    Previously we are using one measure column which will gives the count.Now the current requirement is to get multiple measures in measure hierarchy.
    For Example
    Measure
    Count
    SalesCount(count*Sales/10)
    CustomerCount(count*customer/10)
    In the fact we will be having only column called "count".
    So,I created the remaining two user defined dimension elements and applied formula in filters.
    When i am using individual dimension element in measure hierarchy the data is coming correct,However when I am combing these three hierarchies under measure hierarchiy I am getting no data.Can someone help me out how to resolve this issue
    Thanks,
    SatyaB

    Thanks Gleen.
    This is how the actual scenerio,currently i am creating a cube for testing domain.
    For all defects we will having a column called defect count.Now there are asking a new requirement to add addtional metrics contains sev1open defect,sev2 open defect etc...
    So,I created hierarchy like this
    Measures(Hierarchy)
    Count
    SalesMeasure
    For this member I returned in filter as ( 'contains'( connection : 'STATUS', "New" ) and 'contains'( 'TESTING_SEVERITY', "2-High" ))
    However when I am trying build this individually working fine getting correct data
    When I am combining due to overwrite it seems getting no data.Like this I have to create 16 metrics
    Is there any other method where I can proceed further to resolve this issue
    So,can you help me on this Gleen.Thanks
    Regards,
    SatyaB

  • Cant get adobe photoshop element 13

    can't get adobe photoshop element 13 downloaded

    Downloads available:
    Suites and Programs:  CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4 | CS3
    Acrobat:  XI, X | 9,8 | 9 standard
    Premiere Elements:  13 | 12 | 11, 10 | 9, 8, 7 win | 8 mac | 7 mac
    Photoshop Elements:  13 |12 | 11, 10 | 9,8,7 win | 8 mac | 7 mac
    Lightroom:  5.6| 5 | 4 | 3
    Captivate:  8 | 7 | 6 | 5
    Contribute:  CS5 | CS4, CS3
    Download and installation help for Adobe links
    Download and installation help for Prodesigntools links are listed on most linked pages.  They are critical; especially steps 1, 2 and 3.  If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'.

  • How get all child elements from XML

    Hi
    I have one xml i tried to parse that xml using dom parser and i need to get some child elements using java
    <Group>
    <NAME>ABC</NAME>
    <Age>24</AgeC>
    ---------some data here......
    <Group1>
    <group1Category>
    <NAME>ABCTest</NAME>
    <age>27</Age>
    ----Some data here
    <group1subcategory>
    <subcategory>
    <NAME>ABCDEF</NAME>
    <age>28</Age>
    my intention was
    get group name (here ABC) i need all other name value from group1category ,group1 subcategory but pblm that
    my xml contains any number of Group nodes...but only i want name contains ABC
    i wriiten code like this
    DocumentBuilderFactory factory = DocumentBuilderFactory
    .newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(xmlFile);
    NodeList nodeList = document.getElementsByTagName("*");
    for (int i = 0; i < nodeList.getLength(); i++)
    Element element = (Element) nodeList.item(i);
    what is next step i need to do..please help

    964749 wrote:
    Sorry for inconvenience caused..i only asked if any ideas i not ask any body to spent time for me...
    This is simple code developed using xpath..i not know how i proceed further
    public class Demo {
    public static void main(String[] args) {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    try {
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    Document dDoc = builder.parse("hello.xml");
    XPath xpath = XPathFactory.newInstance().newXPath();
    javax.xml.xpath.XPathExpression expr = xpath.compile("//Group/NAME");
    Object Name= expr.evaluate(dDoc, XPathConstants.STRING);
    System.out.println(Name);
    } catch (Exception e) {
    e.printStackTrace();
    i need get group name (here ABC) i need all other name value from group1category ,group1 subcategory but pblm that
    ..how i done in XPATH and also do manipulation of remining result...
    i also try with DOM like
    NodeList nodeList = document.getElementsByTagName("GROUP");
    for (int i = 0; i < nodeList.getLength(); i++)
    Element element = (Element) nodeList.item(i);
    if (element.getNodeName().matches("ECUC-MODULE-DEF"))
    String str=((Element) nodeList.item(i)).getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue();
    if(str.equalsIgnoreCase("abc")){
    NodeList children = element.getChildNodes();
    for (int k = 0; k < children.getLength(); k++) {
    Node child = children.item(k);
    System.out.println("children"+children.getLength());
    if (child.getNodeType() != Node.TEXT_NODE) {
    if(child.getNodeName().equalsIgnoreCase("Group1"))
    how iterate for particular ABC name to group1 and subcategoryFew things
    1. Use code tags to format code
    2. Explain the problem statement clearly. Take time to formulate your question. Explain what you expect from your code and what you are getting along with any exceptions that are being thrown

  • How to get the last element of a structure in a textfield in DesignStudio

    Hello,
    how can I get the last element of a structure within a bex query?
    Within the structure we are working with dates that dynamically are buiId (input date - offsets for several months).
    I have to show the last value in a single textfield within DesignStudio.
    Regards
    Frank

    Hi Frank,
    in DS 1.3 you can use forEach function to get the last element of BEx structure (or n-th element in general using if condition)
    var array = DS_CROSSTAB1.getMembers("DHGY5D6XEFO1K45SB00BXFH7A",10);
    var lastMember="";
    array.forEach(function(element, index) {
           lastMember = element.text;
    TEXT_1.setText("Last structure element: "+lastMember);

  • How to get Focused UI element on the Window in 7.01

    HI,
      We were on 7.00 and recently upgraded to 7.01. we have a problem with the upgrade.. The window object no more holds the Focus . Here is the code ...  lo_curr_window->focus is blank all the  times.. This was working fine till 7.00 and now it stopped working..
    data:lo_window_manager      type ref to if_wd_window_manager,
            lo_api_component       type ref to if_wd_component.
      data: lo_clnt_appl type ref to cl_wdr_client_component,"CL_WDR_CLIENT_APPLICATION,
              ls_view_mgrs type wdr_viewman_line,
              lo_curr_window type ref to cl_wdr_window,
              ls_focus type wdr_focus,
              lo_uielem type ref to cl_wd_uielement,
              lv_path type string,
              lo_selected_elem type ref to if_wd_context_element,
              lt_strtab type table of string,
              lv_colname type string,
              lv_tablen type int4.
      lo_api_component  = wd_comp_controller->wd_get_api( ).
      lo_window_manager = lo_api_component->get_window_manager( ).
      lo_clnt_appl ?= lo_window_manager.
      read table lo_clnt_appl->view_managers_for_window
                  into ls_view_mgrs with key name = `ZWD_TEST`.
      if sy-subrc = 0.
      get the window in which this interface view is embedded
        lo_curr_window = ls_view_mgrs-view_manager->get_window_recursive( ).
        if lo_curr_window is initial.
          lo_curr_window = wdr_task=>application->application_window->get_active_modal_window( ).
        endif.
        if lo_curr_window is not initial.
          ls_focus = lo_curr_window->focus.
          lo_uielem ?= ls_focus-view_element.
       endif.
      endif.
    Thanks
    Mahesh

    You seem to be utlitzing SAP internal APIs - so a change in behaviour between releases certainly seems possible. Refer to the online help to find out which APIs are safe to use:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/64/be5b4150b38147e10000000a1550b0/frameset.htm
    What exactly are you trying to acomplish?  From your code you seem to be trying to get the UI element that has the current focus. Is that correct?  To what purpose?
    Perhaps you should review the online help section on Focus Handling:
    vhttp://help.sap.com/saphelp_nw70ehp1/helpdata/en/c0/800f02bb734dd9977a64a8a7e87fe3/frameset.htm

  • My hard drive's gone, I did repair it and now I'd like to get my 'photoshop Elements 7 back, but got a message saying that the serial number is incorrect and it's not. can you help me, please?

    My hard drive's gone, I did repair it and now I'd like to get my 'photoshop Elements 7 back, but got a message saying that the serial number is incorrect and it's not. can you help me, please?

    Mseixas you can try running the CC Cleaner Tool located at Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6 - http://helpx.adobe.com/creative-suite/kb/cs5-cleaner-tool-installation-problems.html and then reinstalling.

  • How to get the context element of a F4 help of a column in ALV table?

    Hello!
    I know to get the context element of the current row normally through
    lo_el = WDEVENT->get_context_element( 'CONTEXT_ELEMENT' ).
    or: lo_el = lo_nd->get_element( index = r-parm->index ).
    But this time, I have a F4 help on the cell of a column. After clicking on the F4 help I need to get the current context element. Do you have any idea, to help me?
    Many thanks!
    regards
    Meer

    Hello,
    Kindly close the thread if your query is resolved now.
    Thanks
    Pradeep

  • Number of elements - Dimensional Hierarchy

    Hi,
    In a *'Dimensional Hierarchy'*, while creating a new *'Parent level'*, a 'Logical Level' dialogue box prompts for entering *'Number of elements at this Level'*+. What is its significance ?
    What is achieved by+ *'Number of elements at this Level'* +?+
    Thanks in Advance & Regards,
    Deeba

    Hi deeba,
    Its not mandatory to specify the number of elements in hierarchy....if you wont mention also by default it takes the value of 1.....Above vino gave you the link for explanation.
    Hope it helps you...Award points and close the thread.
    By,
    KK

  • New Adobe Photoshop elements 11-can not share pictures. I do use AOL email. Get error of "Elements 11 Organ. has stopped working,  I have looked into sharing tab and my only option is Adobe email settings.  I do have outlook set up to work on computer run

    New Adobe Photoshop elements 11-can not share pictures. I do use AOL email. Get error of "Elements 11 Organ. has stopped working,  I have looked into sharing tab and my only option is Adobe email settings.  I do have outlook set up to work on computer running windows 8.1  Please help, Mainly use to share pictures.  Thanks!

    One thing puzzles me:
    RedClayFarmer wrote:
    I then found one suggestion that the problem might involve permissions. The suggestion was to right click PhotoshopElementsOrganizer.exe in its installation folder (which on my computer is at at D:\Photo\Elements 11 Organizer) and run Organizer as an administrator. This also failed.
    I don't understand why running the exe from the installation folder would have worked.
    I would have simply tried to run that exe from its real location :
    Sorry, I can't help you more about permissions...

  • My Photoshop 9 Stopped working I get the message "Elements 9 Organizer has stopped working"

    My photoshop 9 program stopped working after using Adobe Premiere 9 to generate a slide show using Adobe Photoshop 9 organizer to place photos. The program crashed as I was attempting to burn a DVD. After this happened, I no longer could access the organizer in Photoshop 9. I get the message "Elements 9 organizer has stopped working" " A problem caused the program to stop working correctly, windows will close the program and notify you of a solution is found"
    I tried unistalling Photoshop 9 and the problem remains.

    Thanks for your suggestion.  I checked the Epson web site and also their technical help, they gave me their latest driver (which didn't work) but also said there were some issues with Apple's Mavericks (OS X 10.9.4) and said I should get back to Apple.  Not sure were this leaves me with Adobe Elements though - perhaps I should reinstall?  Thanks again for your suggestion.

  • Getting next XML Element in a document

    Hello,
    I have an xml JDom Document and I need to get, given the name of an element, the next element in the document.
    For example, with this document:
    <ROOT>
        <APPLE></APPLE>
        <GRAPE></GRAPE>
        <PEAR></PEAR>
        <ORANGE></ORANGE>
        <GRAPE></GRAPE>
        <MELON></MELON>
    </ROOT>I get a string like "ORANGE" and I need o get the next element in the document (GRAPE).
    And if I get "GRAPE", I have to get "PEAR" and "MELON".
    Is there anyway to get the following element without checking all the document elements?
    Thank you

    Is there anyway to get the following element without
    checking all the document elements?Obviously not. But why is "not checking all the document elements" a requirement?

  • Function module to get the wbs element by entering Assignment No.

    Is there any Function module to get the wbs element by entering Assignment No.???????
    Thanks and regards
    Manish Thakur

    hi Manish,
    Just look at this function module.
    function wbs_assignment_check.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(I_COMPONENT) LIKE  RESBDGET STRUCTURE  RESBDGET
    *"     REFERENCE(I_PSPEL) LIKE  RESB-PSPEL
    *"     REFERENCE(I_RFPNT) LIKE  AFVC-RFPNT
    *"  EXPORTING
    *"     REFERENCE(E_PSPEL) LIKE  RESB-PSPEL
      e_pspel = i_pspel.
    endfunction.
    hope this helps u
    REWARD IF USEFUL
    thanks and regards
    suma sailaja

  • How to get selection screen elements and its table reference of a report ?

    halo experts
    How can I get selection screen elements and its table reference of a report ? . I tried rs_refresh_from_select_options. But I am unable to get the table and field it is referring to
    For eg if my selection screen 1000 is
    parameters: p_carrid type spfli-carrid,
    select-options :s-_connid type sflight-connid.
    is there any Fm or method which gives me what are the screen elements( p_carrid and s_connid ) and what table( splfi and sflight ) and field ( carrid and conid )it is referring to ?

    The following code is an example of how you might dynamically determine all your PARAMETERS and SELECT-OPTIONS variables at run time.  The PARAMETERS and SELECT-OPTIONS only point to a dictionary element--not a specific table.  Even though you may say "spfli-carrid" or "sflight-connid", the data type really references the dictionary type and not a specific table/structure.
    REPORT  ZTEST_PROG.
    TABLES sflight.
    DATA:
           screen_tab TYPE STANDARD TABLE OF screen,
           wa_screen TYPE screen,
           scrn_nm TYPE string,
           scrn_leftover TYPE string,
           l_type TYPE REF TO cl_abap_typedescr,
           typ_nm TYPE string,
           typ_pre TYPE string.
    FIELD-SYMBOLS <fs_data> TYPE ANY.
    PARAMETERS p_carrid TYPE spfli-carrid.
    SELECT-OPTIONS s_connid FOR sflight-connid.
    INITIALIZATION.
      LOOP AT SCREEN.
        IF screen-group3 = 'PAR'
          OR screen-group3 = 'LOW'.
            APPEND screen TO screen_tab.
        ENDIF.
      ENDLOOP.
    START-OF-SELECTION.
      LOOP AT screen_tab INTO wa_screen.
        ASSIGN (wa_screen-name) TO <fs_data>.
        l_type = cl_abap_typedescr=>describe_by_data( <fs_data> ).
        IF wa_screen-group3 = 'LOW'.
          SPLIT wa_screen-name AT '-' INTO scrn_nm scrn_leftover.
          TRANSLATE scrn_nm TO UPPER CASE.
        ELSE.
          scrn_nm = wa_screen-name.
        ENDIF.
        SPLIT l_type->absolute_name AT '=' INTO typ_pre typ_nm.
        WRITE:
                 / 'Screen Name:  ', scrn_nm,
                 / 'DDIC Type:    ', typ_nm.
      ENDLOOP.
    When you get into defining internal tables you can determine those at run time with cl_abap_structdescr.  The following is an example of how you might do that.  You can loop through the "components_table" and evaluate each field of the structure in this way.
    DATA: structure_reference TYPE REF TO cl_abap_structdescr,
          components_table TYPE abap_compdescr_tab,
          components_structure LIKE LINE OF components_table.
    structure_reference ?= cl_abap_structdescr=>describe_by_data( any_structure ).
    components_table = structure_reference->components.
    I don't know if this answers any of your questions but I hope that some of it is useful.

Maybe you are looking for