Getting position of data after selecting

Hi All,
Need help regarding this...
Say I have a select statement that selects data from it and orders it in some fashion...
Ex:
The list of top 5 earners in a organisation
i.e SELECT ename,sal FROM EMP WHERE sal >(SELECT AVG(sal) FROM EMP) AND ROWNUM<=5 ORDER BY sal DESC;
gives a list say
ename sal
A 5000
B 3000
C 2000
...... and so on ..
is it possible to add one more column and create a view which gives the position of each employee after selecting
say...
ename sal position
A 5000 1
B 3000 2
C 2000 3...
Can anybody help me out please...
so that wn I say position 2 it should give me 'B' as my ename
Edited by: user12842173 on Mar 24, 2010 10:13 PM

SQL> SELECT first_name, last_name, salary, rn_sal sal_position
  2    FROM (SELECT e.first_name,
  3                 e.last_name,
  4                 e.salary,
  5                 AVG(salary) over() avg_sal,
  6                 row_number() over(ORDER BY salary DESC) rn_sal
  7            FROM hr.employees e)
  8   WHERE salary > avg_sal
  9         AND rn_sal <= 5
10   ORDER BY rn_sal;
FIRST_NAME           LAST_NAME                     SALARY SAL_POSITION
Steven               King                        24000,00            1
Neena                Kochhar                     17000,00            2
Lex                  De Haan                     17000,00            3
John                 Russell                     14000,00            4
Karen                Partners                    13500,00            5
SQL>

Similar Messages

  • How to read data after select multiple record by checkbox,

    hi experts
    i  m using simple report with check box , and itab whcih contain records
    how to read data after select multiple record by checkbox,
    thanks

    Hi Prashant,
       Try using this logic.This Code displays the list with check boxes. When you check a checkbox and press a button say 'Select All' or 'De Select all' or 'Display'. It will read the data of those records.
    DATA :
      fs_flight TYPE type_s_flight,
      fs_flight1 TYPE type_s_flight1.
    * Internal tables to hold Flight  Details                             *
    DATA :
      t_flight LIKE
      STANDARD TABLE
            OF fs_flight,
      t_flight1 LIKE
       STANDARD TABLE
             OF fs_flight1.
    SET PF-STATUS 'SELECT' .
    PERFORM selection.
    PERFORM displaybasic .
    *                      AT USER COMMAND EVENT                          *
    AT USER-COMMAND.
      PERFORM selectall .
    *&      Form  SELECTION
    *      Select query to reteive data from SPFLI table
    *  There are no interface parameters to be passed to this subroutine.
    FORM selection .
      SELECT  carrid                       " Airline Code
              connid                       " Flight Connection Number                  
        FROM  spfli
        INTO TABLE t_flight.
      DESCRIBE TABLE t_flight LINES w_lines .
    ENDFORM.                               " SELECTION
    *&      Form  DISPLAYBASIC
    *      Display the basic list with SPFLI data
    *  There are no interface parameters to be passed to this subroutine.
    FORM displaybasic .
      LOOP AT t_flight INTO fs_flight.
        WRITE :
             w_check AS CHECKBOX,
             w_mark,
             fs_flight-carrid UNDER text-001,
             fs_flight-connid UNDER text-002.
      ENDLOOP.                             " LOOP AT T_FLIGHT..
      CLEAR fs_flight-carrid .
      CLEAR fs_flight-connid.
    ENDFORM.                               " DISPLAYBASIC
    *&      Form  SELECTALL
    *      To check all the checkboxes with a 'selectall' push button
    *  There are no interface parameters to be passed to this subroutine.
    FORM selectall .
      CASE sy-ucomm.
        WHEN 'SELECT_ALL'.
          w_check = 'X'.
          w_line = 4 .
          DO w_lines TIMES.
            READ LINE w_line .
            MODIFY LINE w_line FIELD VALUE w_check .
            ADD 1 TO w_line .
          ENDDO.                           " DO W_LINES TIMES
          CLEAR w_line.
        WHEN 'DESELECTAL'.
          w_check = space.
          w_line = 4 .
          DO w_lines TIMES.
            READ LINE w_line FIELD VALUE w_mark .
            IF w_mark = space .
              MODIFY LINE w_line FIELD VALUE w_check .
            ENDIF.                         " IF W_MARK = SPACE
            ADD 1 TO w_line .
          ENDDO.                           " DO W_LINES TIMES
        WHEN 'DISPLAY'.
    IF sy-lilli BETWEEN 4 AND w_lines .
        DO w_lines TIMES.
          READ LINE w_num FIELD VALUE w_check INTO w_check
                                     fs_flight-carrid INTO fs_flight-carrid
                                     fs_flight-connid INTO fs_flight-connid.
          IF sy-subrc = 0.
            IF w_check = 'X'
              SELECT  carrid
                      connid
                      fldate               " Flight date
                      seatsmax             " Maximum capacity in economy
                      seatsocc             " Occupied seats in economy class
                FROM  sflight
                INTO  TABLE t_flight1
               WHERE  carrid = fs_flight-carrid
                 AND  connid = fs_flight-connid.
              LOOP AT t_flight1 INTO fs_flight1.
                WRITE :
                  / fs_flight-carrid UNDER text-001,
                    fs_flight-connid UNDER text-002,
                    fs_flight1-fldate UNDER text-007,
                    fs_flight1-seatsmax UNDER text-008,
                    fs_flight1-seatsocc UNDER text-009.
              ENDLOOP.
            ENDIF.                         " IF SY-SUBRC = 0
          ENDIF.                           " IF W_CHECK = 'X'.
          ADD 1 TO w_num.
        ENDDO.                             " DO W_LINES TIMES
        CLEAR w_check.
        w_num = 0.
      ELSE .
        MESSAGE 'INVALID CURSOR POSITION ' TYPE 'E' .
      ENDIF.                               " IF SY-LILLI BETWEEN..
    ENDCASE.                             " CASE SY-UCOMM
    ENDFORM.                               " SELECTALL
    Much Regards,
    Amuktha.

  • How can i get back my data after i restored my iphone and accidentally created a new iphone ac.

    how can i get back my data after i restored my iphone and accidentally created a new iphone ac.
    it did a back up when i started my restored iphone and i cant retrieve my previous backup while i didnt back up on icloud....
    the new ac is actually the same apple id as the one i used. I lost all my contact, photos and data of whatsapp...
    what can i do...help!

    I don't know if this is a similar problem but I wrote 2 notes yesterday on my iphone. I opened my mail to print them and they appeared as notes but wouldn't load. Then I looked at them on my iphone and I could see the notes but they quickly updated to blank with a time of the last edit the same time I tried opening them on my computer.
    Yesterday I updated to 4.3.4  I don't know if somehow that affected them. Are they stored somewhere else. Can I get them back?

  • Short dump while saving data after selecting '#' for variable in WI

    Hello All,
    We have a selection variable in our webinterface on company code.After selecting '#',i am entering data and while saving it goes to dump.
    but client wants to have an error message displayed after saving data instead of runtime error (dump).so that user can select required company code.
    Error analysis is:
    A RAISE statement in the program "SAPLRSDRI" raised the exception   
    condition "ILLEGAL_INPUT".                                          
    Since the exception was not intercepted by a superior program       
    in the hierarchy, processing was terminated.                        
    Short description of exception condition:                           
    For detailed documentation of the exception condition, use          
    Transaction SE37 (Function Library). You can take the called        
    function module from the display of active calls.                   
    Is there any way to get desired  result?
    Thanks

    Hello Murali,
    What you would need to do is to change the attributes of the variable.
    1. In BPS0, you can make it as a mandatory entry.
    2. In the web layout, you can create a variable for Company code and force the user to choose a value from a dropdown list.
    The specific approach would depend on how the layout is being called and how it has been setup.
    Hope this helps.
    Sunil

  • How can I get a list view after selecting "see all"?

    I just updated to iTunes 12.  I've looked on the net for this but couldn't find anything on it.
    Previously when I searched for something in the iTunes store I'd pick a certain category of media (podcasts, for example).  It would give me the first few results and then I could select "see all."  Then get a list view and sort it.
    Now when I click on "see all" I get an album cover view.  NOT a list view.  And I have no way to sort the results.  I usually sort by time.
    What's odd is when I'm still on the initial page you get after making a search I *can* sort the results.  But only the first 10.
    Basically, I need a way to sort all of my search results by time.  Either after selecting "see all" or having iTunes show many more than 10 results.
    This was possible (and the default, I think) in previous versions.  I've looked through every menu and I don't see a way to turn this functionality back on.
    Thanks.

    Hi,
    There is no such PowerShell command can achiev this. Maybe you can use a script to get the user name with folder redirection enabled. However, I am not familiar with writing script, and it would be better for you to ask in script forum below for professional
    assistance:
    http://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG&filter=alltypes&sort=lastpostdesc
    Best Regards,
    Mandy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • How to get back WhatsApp data after hard reset. Backup disappeared

    So after suffering phone issues for months but being a new mum and having no time to reset my phone to factory default, so I could send it away, I finally last night thought I'd backed up everything, ready to reset!
    All my photos and videos are on google cloud and my 64gb SD card too. I'd backed up my SMS with an app and backed up all app data to Google. I'd also used the Sony backup/restore app to backup all my apps and I thought I'd backed up WhatsApp in its settings/chats/backup.
    I know WhatsApp makes a backup at 4am every night in case you reinstall it and so I thought I was fool proofed and reset/erased internal memory.
    On reinstaling, Google automatically started downloading apps again, which I didn't get, as I thought my backup from the Sony phone app would restore everything so i cancelled that.
    WhatsApp hadn't installed yet so I installed it from the play store and it said it could restore my data, so I said yes! BUT it restored a backup from June 26th 2015, not from the last day as I'd have thought from 4am backups!
    So I uninstalled WhatsApp and went to restore from the app backup file, which I could see had a backup of WhatsApp from 1st August 2015. Prob was it kept crashing on restoring the opera browser. It completed once but WhatsApp hadn't installed. So I ran it over and over. It still crashed on Opera.
    So I used Es file explorer to unhide files and found the Backup on my SD card with 1st August and inside could see WhatsApp. I cut the opera backup file from the back up folder and pasted it somewhere safe to see if the restore would not run. But when I went back to the Backup/restore app and clicked restore, my 1st August back up folder had disappeared! I went back to Es file explorer and sure enough, the folder was gone from the apps backup folders!
    It isn't in any recycle bin and now I think I've lost a month's worth of WhatsApp messages, which are really important to me! When I get chance, I'm going to put the SD card in my Mac and see if I can find the file there but has anyone got any advice on why the folder disappeared, when I only cut the opera backup from the folder?

    P.s, all hidden files are shown in es file explorer as this backup folder was hidden originally. It has a '.' in front. So I'm pretty sure the folder it's gone, but as I've not erased my phone again, shouldn't the folder be somewhere in my SD card still and how can I find it using my Mac?

  • Not getting delta master data after refresh

    Hello,
    We have just refreshed our QA (BW and R/3) environments from our production environments.  It was a synchronized restore.  We have done this multiple times in the past and have not run into this problem before.
    Everything checks out fine - full master data loads fine, and delta transaction data loads fine, but our master data loads that are deltas retreive no data and produce the following message:
    Selection conditions replaced by last init. selection conditions
    Message no. RSM1036
    Diagnosis
    Selection conditions replaced by init. selection conditions.
    No new selections can be made when requesting delta data from a 2.0 extractor.
    Delta selections are composed of the total quantity of all the selections of all the sucessful init. requests for this DataSource.
    I have looked this up here and in OSS.  What I have found would indicate that we have multiple inits.  However, when I look at the Initialization Options for Source System from within the infopkg, there is only one.  Also, RSA7 appears to be fine on R/3.
    Is there table or setting that may have been missed or some other place I need to check? 
    Any ideas or suggestions would be appreciated.
    Thanks,
    Kelley

    Thanks, but I do not understand what exactly to look for in that table.  What fields in that table should I check and for what?
    I have compared rssdlinit on BW with roosprmsc on R/3 and they match.  I have checked other tables too and they look fine. 
    There was a mistake made when the system was refreshed that may have caused this problem.  That would at least explain why we are having this problem now and did not before.
    I tested one of our delta master data objects (0material_text).  I deleted the init from within the infopkg.  Then I ran the infopkg to init with no data transfer.  That appeared to work - resulting in 1 record which is normal for an init delta with no data.  Then changed material text on R/3 and ran the infopkg with delta update.  It still gave the same message that I listed in my first post, and it retrieved 0 records.
    Any ideas?
    Thanks,
    Kelley

  • Can not search app store i get white page only after selecting a search option

    when searching for apps, i see the various apps that meet my selection, but when i click on any of them, all i see is a blank page,  same thing happens in categories, Fetured, charts, etc.

    Hello julielvanova,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    Have a nice day,
    Mario

  • Get data after truncate

    hi,
    how can i get back my data after truncating the table.
    regards
    Kiran Sankpal

    Hi Kiran,
    Table backup is the only way to restore data of a truncated table, it is possible to get deleted data back but not data of a truncated table. Refer Flashback
    *009*

  • How can I get the image data from Clipboard with LV

    Anybody knows How can get the image data after pressd "print screen button" with LV?
    I want to program a software which can save a image as a bmp or jpeg etc, and the image data is from pressed print screen button. 
    How to get it out from clipboard. I am trapping about. thanks in advance.
    Try to make everything Automatic

    You can have a look at Rolf Kalbermatter's post here (give him stars) or, if you're using scripting, you can use the Application class Get Clipboard Image method.
    Try to take over the world!

  • LOV is slow after selecting a value its taking much time to default

    Hi,
    I have a dependent LOV. Master LOV is executing fine and its populatin into the field fastly. But Child LOV is very slow after selecting a value its taking much time to default.
    Can any one please help me if there is any way to default the value fast after selecting a value?
    Thanks,
    Mahesh

    Hi Gyan,
    Same issues in TST and PROD instances.
    In my search criteria if i get 1 record, even after selecting that value its taking much time to default that value into the field.
    Please advice. Thanks for your quick resp.
    Thanks,
    Mahesh

  • Data Error in the Query/Report after selective data deletion for infocube

    Hi Experts,
    Please advise what i was missing and what went wrong...
    I got a Query (Forecast) on a Multicube...which is based on 2 Infocubes with Aggregates...
    As i identified some data discrepency..yesteraday i performed selective data deleation on one of the Infocube
    and executed report yesteraday and the results in the query are correct...
    When today i executed the same report i am getting different results..
    When i compared the results of the report with that of data in cube they are not matching
    The report is not displaying the data in cube..for some rows it is displaying the data in the cube but for some rows it is just displaying same as the above row
    there is no data loaded into info cube after selective deleation
    Do i need to perform request compression and fill the aggregated after selective deleation
    Please advise what went wrong

    Hi Venkat,
    No i haven't done anything on aggregates before or after selective delete
    As there is not data load after the selective delete according to SAP Manual we don't need to perform any thing on aggregates...as selective data deletion on cube will delete data from aggregates as well
    Please update how to identify error

  • How to Put Date in a Textbox after Select

    Hi, DWMX. How do i put todays date into a text box after
    selecting an item from a ListBox. ie I want to change the staus in
    the Listbox and have the StatusChangedOn Text box filled
    automatically so it gets saved on submit.. I guess it's a bit of
    java which i don;t know any of. I am using VBScript for the server
    code. Thanks. Dave(UK)

    Dave
    If this is being a saved to a database simple set the default
    value of the
    database field to record the server time when the entry is
    made. In Access
    this is Date(), in msSQL it is getDate()
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "Dave(UK)" <[email protected]> wrote in
    message
    news:e5v91r$olj$[email protected]..
    > Hi, DWMX. How do i put todays date into a text box after
    selecting an
    > item
    > from a ListBox. ie I want to change the staus in the
    Listbox and have the
    > StatusChangedOn Text box filled automatically so it gets
    saved on submit..
    > I
    > guess it's a bit of java which i don;t know any of. I am
    using VBScript
    > for
    > the server code. Thanks. Dave(UK)
    >

  • Parse the URL column to get data after 5th "/"

    Hi All,
    I have a url column that i need to parse to get the data after 5th Slash. can anyone help me here.
    Table : URLData
    url
    http://www.abc.com/OurJourneys/Ourlife/the-Great-Explorers/dp
    http://www.abc.com/OurJourneys/Ourlife/Times-new-time/OurJourneys.aspx year=2015&region=Antaica&type=Sl
    http://www.abc.com
    I result should be below data
    the-Great-Explorers
    Times-new-time
    Any help would be much appreciated

    The code you gave me works fine but it always gets me second last position.
    http://www.abc.com/OurJourneys/Ourlife/the-Great-Explorers/dp
    http://www.abc.com/OurJourneys/Ourlife/Times-new-time/OurJourneys.aspx
    year=2015&region=Antaica&type
    http://www.abc.com
    what if i want to get 3rd last position.
    http://www.abc.com/OurJourneys/Ourlife/the-Great-Explorers/dp
    http://www.abc.com/OurJourneys/Ourlife/Times-new-time/OurJourneys.aspx
    year=2015&region=Antaica&type
    http://www.abc.com
    Can you help me to get code for that.

  • Problem in displaying data onto Form after selecting from table.

    Hi there,
    I keep hitting this error when I tried to display the data after the selection from table. Using backing beans w data control to do it
    Err: java.lang.ClassCastException: java.util.Collections$SingletonList cannot be cast to java.lang.Integer
    Table used ArrayList to retrieve out the wanted data. E.g uses A object
    To display: selected data to retrieve the selected row to display as a read-only form layout below the table. E.g. need to get A.getName() to match with B object B.getName() then uses the B object to retrieve out the data.
    Anyone know how to do it?

    Hi
    use the follwing code
    int rowcount = wdContext.node<Name>().size();
    while(rs.next())
    IPrivate<ViewName>.I<Name>Element tabnode =wdContext.node<Name>().get<Name>ElementAt(i);
    tabnode.nodeAuthoriseNode().invalidate();
    tabnode.nodeAuthoriseNode().addElement(0,authele);
    tabnode.nodeAuthoriseNode().setLeadSelection(0);
    wend
    Regards
    Dhinakar

Maybe you are looking for