How to get all minimum values for a table of unique records?

I need to get the list of minimum value records for a table which has the below structure and data
create table emp (name varchar2(50),org varchar2(50),desig varchar2(50),salary number(10),year number(10));
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',3000,2005);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',4000,2007);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',7000,2007);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',7000,2008);
insert into emp (name,org,desig,salary,year) values ('emp1','org1','mgr',7000,2010);
commit;
SELECT e.name,e.org,e.desig,min(e.year) FROM emp e,(
SELECT e1.name,e1.org,e1.desig,e1.salary FROM emp e1
GROUP BY (e1.name,e1.org,e1.desig,e1.salary)
HAVING COUNT(*) >1) min_query
WHERE min_query.name = e.name AND min_query.org = e.org AND min_query.desig =e.desig
AND min_query.salary = e.salary
group by (e.name,e.org,e.desig);With the above query i can get the least value year where the emp has maximum salary. It will return only one record. But i want to all the records which are minimum compare to the max year value
Required output
emp1     org1     mgr     7000     2008
emp1     org1     mgr     7000     2007Please help me with this..

Frank,
Can I write the query like this in case of duplicates?
Definitely there would have been a better way than the query I've written.
WITH      got_analytics     AS
     SELECT     name, org, desig, salary, year
     ,     MAX (SALARY)  OVER ( PARTITION BY  NAME, ORG, DESIG)          AS MAX_SALARY
     ,     ROW_NUMBER () OVER ( PARTITION BY  NAME, ORG, DESIG, SALARY
                                ORDER BY        year  DESC
                       )                              AS YEAR_NUM
       FROM    (SELECT 'emp1' AS NAME, 'org1' AS ORG, 'mgr' AS DESIG, 3000 AS SALARY, 2005 AS YEAR FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL)
SELECT     name, org, desig, salary, year
FROM     got_analytics
WHERE     salary          = max_salary
AND     YEAR_NUM     > 1
Result:
emp1     org1     mgr     7000     2010
emp1     org1     mgr     7000     2008
emp1     org1     mgr     7000     2007
emp1     org1     mgr     7000     2007
WITH      got_analytics     AS
     SELECT     name, org, desig, salary, year
     ,     MAX (SALARY)  OVER ( PARTITION BY  NAME, ORG, DESIG)          AS MAX_SALARY
     ,     ROW_NUMBER () OVER ( PARTITION BY  NAME, ORG, DESIG, SALARY
                                ORDER BY        year  DESC
                       )                              AS YEAR_NUM
  ,     ROW_NUMBER () OVER ( PARTITION BY  NAME, ORG, DESIG, SALARY, Year
                                ORDER BY        YEAR  DESC
                       )                              AS year_num2
     FROM    (SELECT 'emp1' AS NAME, 'org1' AS ORG, 'mgr' AS DESIG, 3000 AS SALARY, 2005 AS YEAR FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',4000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2007 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2008 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL UNION ALL
SELECT 'emp1','org1','mgr',7000,2010 FROM DUAL)
SELECT     name, org, desig, salary, year
FROM     got_analytics
WHERE     salary          = max_salary
AND     YEAR_NUM     > 1
AND YEAR_NUM2 < 2
Result:
emp1     org1     mgr     7000     2008
emp1     org1     mgr     7000     2007

Similar Messages

  • How to get all the values from the dropdown menu

    How to get all the values from the dropdown menu
    I need to be able to extract all values from the dropdown menu; I know how to get all those values as a string, but I need to be able to access each item; (the value in a dropdown menu will change dynamically)
    How do I get number of item is selection dropdown?
    How do I extract a ?name? for each value, one by one?
    How do I change a selection by referring to particular index of the item in a dropdown menu?
    Here is the Path to dropdown menu that I'm trying to access (form contains number of similar dropdowns)
    RSWApp.om.GetElementByPath "window(index=0).form(id=""aspnetForm"" | action=""advancedsearch.aspx"" | index=0).formelement[SELECT](name=""ctl00$MainContent$hardwareBrand"" | id=""ctl00_MainContent_hardwareBrand"" | index=16)", element
    Message was edited by: testtest

    The findElement method allows various attributes to be used to search. Take the following two examples for the element below:
    <Select Name=ProdType ID=testProd>
    </Select>
    I can find the element based on its name or any other attribute, I just need to specify what I am looking for. To find it by name I would do the following:
    Set x = RSWApp.om.FindElement("ProdType","SELECT","Name")
    If I want to search by id I could do the following:
    Set x = RSWApp.om.FindElement("testProd","SELECT","ID")
    Usually you will use whatever is available. Since the select element has no name or ID on the Empirix home page, I used the onChange attribute. You can use any attribute as long as you specify which one you are using (last argument in these examples)
    You can use the FindElement to grab links, text boxes, etc.
    The next example grabs from a link on a page
    Home
    Set x = RSWApp.om.FindElement("Home","A","innerText")
    I hope this helps clear it up.

  • How to get all the values in one column of a JTable

    How to get all the values in one column of a JTable as a Collection of String.
    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column.

    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column. You could always write a custom TableModel that stores the data in the format you want it. It would probably be about 50 lines of code. Or you could write a loop in 3 lines of code. I'll let you decide which approach you want to take.

  • How to get all the values of a variable with F4 with checkboxes to select

    Dear Experts,
    After Executing a query by giving let 3 values(Out of 10 Values) to a variable.
    To give 2 more input values to the same variable(i.e.,total I wanted to give 5 inputs this time ),after refreshing the query,for that variable if I click F4, I am seeing the historical values(i.e.,3) and remaining 7 values also But with out any Check Boxes besides them to select the 2 inputs.
    In the same F4 Screen, If I click all values(an Icon at The bottom),then also Im seeing but no check Box.
    I hve tried by deleting the Delete Personalization also,but no use.
    Please tell me How to get all the values with F4 with check boxes to select ,whatever I want??
    Thanks in advance

    Take a look at the InfoObject and go to the Business Explorer tab. If the 'Query Def. Filter Value Selection' is set to 'Only Values in InfoProvider', you're only going to get the values in F4 that exist in the InfoProvider, not everything in the Master Data. This would need to be changed to the value of 'Values in Master Data Table' if you want it to show everything possible when F4 is chosen.
    Likewise, you're going to need to look at the query and go to the Advanced tab for the InfoObject. Make sure that the radio button for 'Values in Master Data Table' is selected. If not, then you should change that selection.

  • How to get item field values for old versions?

    I need to be able to query old field values from previous versions of items in a SharePoint list. I can't execute code on the server (it needs to work with SharePoint Online/O365 for a start).
    So far the ONLY API I've that lets me do this is the lists.asmx GetVersionCollection SOAP call.
    This lets me specify a single field name and returns an XML structure with the values for the various versions, along with the modification time and who made the change - but NO reliable way of actually identifying *which* version (i.e. an ID or label). That
    is, if I know I need to fetch the Title value from version 512 ("1.0") of item 1 in list "Documents", I don't see how to reliably parse the results to determine which entry is version 512. While they may be returned in order, in many cases
    the entries are actually missing when there was no field value present (or perhaps when the field hadn't been created yet). I've tried comparing the Modified date to the Created date of the corresponding FileVersion item (which I can get via CSOM or REST),
    and while it works some of the time, it's not reliable. I've also looked at the output from the lists.asmx GetVersion API but I don't see how that's useful either, as the Created property for all versions always seems to be just the date the file was originally
    created.
    It does seem odd to me that there's not a neat way of doing this - if I need to return information for several fields but just for a single version, I have to make a whole lot of requests that return far more info than I need, and then I need to figure out
    how to parse the returned text in the case of, say, multiple-value taxonomy fields etc.
    Anyone tried doing anything similar here?
    Thanks
    Dylan

    try these links:
    https://support.office.microsoft.com/en-us/article/Track-and-view-version-information-for-SharePoint-list-items-2d69d936-fb0b-4c84-830e-11708e6ec317?CorrelationId=f87cf6ea-8cbf-446a-a4a0-e2c3a86b3425&ui=en-US&rs=en-US&ad=US
    https://social.technet.microsoft.com/Forums/en-US/e48ff216-7ed1-4b20-9f21-d496b1583eea/how-to-get-item-field-values-for-old-versions?forum=sharepointdevelopment
    http://sharepoint.stackexchange.com/questions/20019/get-meta-data-from-a-previous-version-of-a-document-through-webservice-in-moss-2
    http://sharepoint.stackexchange.com/questions/121594/getting-information-from-previous-versions-of-a-sp-list-using-csom
    Please mark answer as correct if it is correct else vote for it if you find it useful Happy SharePointing

  • How to get count of rows for a table?

    Hi,
    How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
    Regards,
    Devashish

    Hi Devashish,
    WdContext.node<Your_node_name>().size() will give you the no: of rows.
    This should be the node that is bound to the table's datasource property.
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
    You can access an attribute of a particular row as
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
    Hope this helps,
    Best Regards,
    Nibu.
    Message was edited by: Nibu Wilson

  • How to get all the values in the Select-option.

    Hi,
    I got the select-option field so_week, for eg. If I give 200923 to 200926 (year and week)  in the selection screen and then I need to pass this value (200923) to the FM 'ZWEEK_GET_FIRST_DAY' to get the first day of the week.
    My question is how can i get all the values from the select option, (i.e) i need to get 200923, 200924,200925, 200926.
    Regards,
    Anbu.

    Hello,
    I will prefer Max's solution. But just for the sake of this req.
    i need to get 200923, 200924,200925, 200926
    i am proposing my soln:
    DATA: V_WEEK TYPE RSCALWEEK.
    SELECT-OPTIONS: S_WEEK FOR V_WEEK NO-EXTENSION OBLIGATORY.
    AT SELECTION-SCREEN.
      DATA:
      V_COUNT TYPE I,
      V_ADD   TYPE I,
      RT_WEEK TYPE RANGE OF RSCALWEEK,
      RS_WEEK LIKE LINE OF RT_WEEK.
      V_COUNT = ( S_WEEK-HIGH - S_WEEK-LOW ) + 1.
      DO V_COUNT TIMES.
        RS_WEEK-SIGN = 'I'.
        RS_WEEK-OPTION = 'EQ'.
        RS_WEEK-LOW = S_WEEK-LOW + V_ADD.
        APPEND RS_WEEK TO RT_WEEK. "RT_WEEK--> Will contain the week values
        CLEAR RS_WEEK.
        V_ADD = V_ADD + 1.
      ENDDO.
    @Max: I was stupid enough not to think of your solution. Need to leave office
    Cheers,
    Suhas

  • How to get all the values from a HashMap? thanks

    hi
    can anyone tell me how to get all the keys and their values contained in a HashMap? thanks

    thanks to u all for ur response, i gues if i need to get both keys and values, i need to use keySet() to get a set of keys first and then using each key to get value. is there any other faster way to get both of them (key and value)? thanks again

  • How to get all authorization objects for a certain authorization profile

    Hi ABAP experts,
    I have the following problem: for a certain authorization profile of a role (created with transaction PFCG) I would like to get all contained authorization objects: e.g. for the contained object PLOG I would like to know/read all corresponding parameter values.
    So:
    - where are these values stored (dictionary table)?
    - is there already a FM or a report to read all authoriation values for a certain authorization profile?
    Thanks in advance.
    Best regards,
    Oliver

    Hi,
    check the following it might useful for you:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a92195a9-0b01-0010-909c-f330ea4a585c
    if helpful reward points are appreciated

  • How to get the purchase value for a purticular price.

    Hi guru's,
    I want to get the purchase value for some materials, in a particular plant and in a particular month. How can I get this data.
    waiting for replies
    thanks
    tuljasingh.

    Hi,
    Refer report ME1P - PO Price History.
    Else Use Reports;
    ME2N - PO List by Document No
    ME2M - PO List by Materials
    ME2L - PO List by Vendors
    ME80FN - General Analysis of Purchase Orders

  • How to get Privacy Policy value for each userprofile in sharepoint 2010?

    In userprofile application, we have defined Privacy Policy of mobilephone feild as optional, so every user has option to choose visibility scope of this property to "Everyone/My Manager/my colegues/Only Me" .
    Now I am trying to get mobilephone value and their selected visibility option for each user.
    I am able to get mobilephone value but I could not get "what each user has chosen as their visibility scope"?

    Hi,
    According to your post, my understanding is that you want to get Privacy Policy value for each userprofile in sharepoint 2010.
    You need to use RunWithElevatedPrivileges method to impersonate user.
    To get the get mobilephone policy, you can use user["CellPhone "].Privacy.
    For more information, you can refer to:
    c# - Getting property privacy with Sharepoint 2010
    How to Programmatically Impersonate Users in SharePoint
    Managing Sharepoint 2010 Profiles Programmatically
    Thanks,
    Linda Li                
    Forum Support
    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]
    Linda Li
    TechNet Community Support

  • How to get all GL accounts for each account in a given bank...

    Hello Experts,
    Is there a way to get all GL accounts for each account in a given house bank?
    IN our company, there are 5 GL accounts for each bank so 1 GL for 1 account. they are for recon, payables,
    receivables, etc. I checked table T012K but it only shows the main GL account. Hope you
    can help me guys. Thank you and take care!

    Try this.. it is based on company code
    here it_cocodes is an internal table containing company codes
      DATA: BEGIN OF it_glaccount OCCURS 0,
        bukrs TYPE bukrs,
        saknr TYPE saknr,
        txt50 TYPE txt50_skat,
       END OF it_glaccount.
      DATA it_glaccount_wa LIKE it_glaccount.
    LOOP AT it_cocodes INTO it_cocodes_wa WHERE ktopl <> ''.
        SELECT bukrs saknr FROM skb1
          INTO CORRESPONDING FIELDS OF it_glaccount_wa
          WHERE bukrs = it_cocodes_wa-bukrs.
          IF sy-subrc = 0.
            SELECT SINGLE txt50 FROM skat INTO it_glaccount_wa-txt50
              WHERE spras = 'E' AND ktopl = it_cocodes_wa-ktopl
              AND saknr = it_glaccount_wa-saknr.
            APPEND it_glaccount_wa TO it_glaccount.
            CLEAR it_glaccount_wa-txt50.
          ENDIF.
        ENDSELECT.
    loop at it_glaccount into it_glaccount_wa.
    write:/....
    endloop.
    refresh...
    clear...
    endloop.

  • How to get edited row values from ADF table?

    JDev 11.
    I have a table which is populated with data from Bean.
    I need to save changes after user make changes in any table cell. InputText is defined for table column component.
    I have defined ValueChangeListener for inputText field and AutoSubmit=true. So when user change value in inputText field, method is called:
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    getSelectedRow();
    SaveMaterial(material);
    This method should call getSelectedRow which take values from selected table row and save them into object:
    private Row getSelectedRow(){
    RichTable table = this.getMaterialTable();
    Iterator selection = table.getSelectedRowKeys().iterator();
    while (selection.hasNext())
    Object key = selection.next();
    table.setRowKey(key);
    Object o = table.getRowData();
    material = (MATERIAL) o;
    System.out.println("Selected Material Desc = "+material.getEnumb());
    return null;
    Problem is that getSelectedRow method doesnt get new (edited) values, old values are still used.
    I have tried to use ActiveButton with same method and it works fine in that case. New values are selected from active row and inserted into object.
    JSF:
    <af:table var="row" rowSelection="single" columnSelection="single"
    value="#{ManageWO.material}" binding="#{ManageWO.materialTable}">
    <af:column sortable="false" headerText="E-number">
    <af:inputText value="#{row.enumb}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    <af:column sortable="false" headerText="Description">
    <af:inputText value="#{row.desc}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
    </af:column>
    </af:table>
    <af:activeCommandToolbarButton text="Save" action="#{ManageWO.EditData}"/>
    What is a correct place from where save method should be called to get new (edited) values from ADF table?
    Thanks.

    Did you look into the valueChangeEvent?
    It has oldValue and newValue attributes.
    public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
    Object oldVal = valueChangeEvent.getOldValue();
    Object newVal = valueChangeEvent.getNewValue();
    // check if you see what you are looking for.....
    getSelectedRow();
    SaveMaterial(material);
    }Timo

  • How to get all possible values of a property

    I have a single-valued restricted property which has a number of predefined values.
    I want to be able to get all of these values to use to populate a drop down list in my portlet.
    Does anyone know how I can do this?

    Hello Angela,
    Here is an example portlet that I wrote for WLPS 2.0. It should work for WLPS 3.1 also, but it
    didn't verify it on 3.1 yet. The key is that you have to use the SchemaManager to get a Schema
    which will allow you to get get PropertyMetaData. See the javadoc for more information.
    Here you go:
    <%-- This JSP page lists the restricted values for a multiple restricted property --%>
    <%@ page import="java.util.*" %>
    <%@ page import="com.beasys.commerce.axiom.util.helper.JNDIHelper,
    com.beasys.commerce.foundation.property.SchemaManagerHome,
    com.beasys.commerce.foundation.property.SchemaManager,
    com.beasys.commerce.foundation.property.Schema,
    com.beasys.commerce.foundation.property.SchemaManagerConstants,
    com.beasys.commerce.foundation.property.PropertyMetaData,
    com.beasys.commerce.axiom.util.ToolkitException,
    java.rmi.RemoteException,
    javax.ejb.CreateException" %>
    <%@ page extends="com.beasys.commerce.axiom.jsp.JspBase" %>
    <%
    I used the admin tool to create a "test" property set with
    a multiple, restricted text property called "restrictedWords". The
    allowable values are "how", "now", "brown", "cow". I selected one
    default value ("brown").
    SchemaManagerHome smh = null;
    try
    smh = (SchemaManagerHome) JNDIHelper.getHome("com.beasys.commerce.foundation.property.SchemaManager");
    catch (ToolkitException e)
    e.printStackTrace();
    PropertyMetaData metaData = null;
    try
    SchemaManager sm = smh.create();
    // Get the schema for the user/group property set called "test"
    Schema schema = sm.getSchema("test", SchemaManagerConstants.USER_TYPE);
    // Get the meta data for the "restrictedWords" property
    metaData = schema.getPropertyMetaData("restrictedWords");
    catch (CreateException e)
    e.printStackTrace();
    catch (RemoteException e)
    e.printStackTrace();
    Collection restrictedValues = metaData.getRestrictedValues();
    Iterator restrictedIter = restrictedValues.iterator();
    while (restrictedIter.hasNext())
    out.println("<br>restricted value is: " + restrictedIter.next());
    %>
    Ture Hoefner
    BEA Systems, Inc.
    2590 Pearl St.
    Suite 110
    Boulder, CO 80302
    www.bea.com
    [att1.html]

  • How to get all checked values from a chaeck box

    Hello
    In my app i have a checkbox called P10_CID with static lov like
    STATIC2:one;1,two;2,three;3,four;4,six;6
    my question is when i check more than one option
    i can not get that value.
    How is it possible to see all the values of the check box that are checked ?
    Regards
    Aris

    Hi Aris,
    Do you have to have checkboxes? Can you use a multiselect list instead?
    If you can, then the following excerpt from the user guide may help you:
    Using HTMLDB_UTIL.STRING_TO_TABLE to Convert Selected Values
    Suppose you had a report on the EMP and DEPT tables that is limited by the
    departments selected from a Department multiple select list. First, you create the
    multiple select item, P1_DEPTNO, using the following query:
    SELECT dname, deptno
    FROM dept
    Second, you return only those employees within the selected departments as follows:
    SELECT ename, job, sal, comm, dname
    FROM emp e, dept d
    WHERE d.deptno = e.deptno
    AND instr(':'||:P1_DEPTNO||':',':'||e.deptno||':') > 0
    Regards
    Andy

Maybe you are looking for

  • Mini Display Port to Dual Link DVI Does Not Work Right

    Somebody said here that this was an isolated problem. Well, I just got my new MacBook Pro 15", used the adapter to hook to the 30" Dell monitor, and it works a few minutes, then the screen distorts. Count me among the isolated problems- it is beginni

  • Finder wants to open SWFs with Illustrator

    My computer seems to think that SWFs (unless I create them personally) should be opened by Illustrator, and I'm tired of having to manually set the "Always open with..." all the time. Is there a permanent fix for this? Thanks for your time.

  • How to run file-to-file scenario

    Hello, I have just done my first exercise in XI, File-to-File Scenario. I ran the scenario in RWB in Component Monitoring by giving the Payload from the Message Mapping.  It ran successfully. But I am not able to run the same scenario by giving my so

  • Macbook pro wifi internet not working

    Hi Everybody, I am recently getting a problem with Wifi. I am using Macbook Pro 13 mid 2010, upgraded from Mac os x lion with wifi patch update. It was working fine, but suddenly my internet stops working. Here is some solutions I already tried: 1. I

  • Failed to install Windows Vista SP2 on iMac

    I was trying to install Windows Vista on my iMac. In fact, I have successfully installed before but I deleted it because something wrong with it. However, the second time I installed was failed (Stuck at "Completing Installation") I tried 4 times and