Select the new value from a line in a group of

I would like on the following query select the value of the new_cost of the column that belongs to the line with the new date in the column m.creation_date, instead of using max (new_cost)
select s.segment1, segment2, m.organization_id, sum(primary_quantity), max(new_cost)
from inv.mtl_material_transactions m, inv.mtl_system_items_b s
where s.segment2 = 1000435
and m.organization_id = 83
and s.organization_id = 136
and m.inventory_item_id = s.inventory_item_id
group by s.segment1, s.segment2, m.organization_id 
order by s.segment1, s.segment2, m.organization_id 
for example, the following table I would choose the new_cost of the line with creation date 20/08/2010 14:37 (line 4)

SEGMENT1 SEGMENT2 ORGANIZATION_ID PRIMARY_QUANTITY NEW_COST CREATION_DATE
1 1000435 83 0,66668 175.500 06/04/2010 16:41
1 1000435 83 1 189.106 22/06/2010-11:54
1 1000435 83 - 0, 58333 189.106 2010-07-19 11:55
1 1000435 83 1 198.459 20/08/2010 14:37
1 1000435 83 - 0, 5 189.106 08/11/2010 18:12

Hello

Another way is to use the FIRST aggregation or the LAST function:

select    s.segment1, segment2, m.organization_id, sum(primary_quantity)
,       MAX (new_cost) KEEP (DENSE_RANK LAST ORDER BY m.creation_date NULLS FIRST)     AS latest_new_cost
from        inv.mtl_material_transactions       m
,        inv.mtl_system_items_b       s
where       s.segment2          = 1000435
and        m.organization_id     = 83
and       s.organization_id     = 136
and       m.inventory_item_id     = s.inventory_item_id
group by  s.segment1, s.segment2, m.organization_id
order by  s.segment1, s.segment2, m.organization_id
;

MAX (new_cost) tells what to do in the case of a tie (where two or more lines in the same group have same latest date_creation). MAX means taking the biggest contenders. If these links are impossible to your table, then it does not matter if you say MAX or MIN it.

Tags: Database

Similar Questions

  • get the new value to select a radio station by ValueChangeListener Bean

    ADF / JDeveloper11g

    Hi Experts,

    Please help what I'm working on one Radio select and populated with a value of VO. I need to get the new value selected by ValueChangeListener Bean. the code as follows. Copy the following code I am old value, but I need to develop some new and current.

    Please help, its urgency.
      public void SlRadio(ValueChangeEvent valueChangeEvent) {
        getBranch();
      }
      public void getBranch() {
        // Add event code here...
    
        DCBindingContainer dcBindings =
          (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    
        // Get a attribute value of the current row of iterator
        DCIteratorBinding iterBind =
          (DCIteratorBinding)dcBindings.get("VOUserBranchList1Iterator");
        String vRtno = (String)iterBind.getCurrentRow().getAttribute("RtNo");
    
        setRtno(vRtno);
        System.out.println("=========Rtng========" + Rtno);
      }
    Thank you.
    Zed
    ======

    Hi Zaza,

    As you are able to get the index of the current selected option button, try upward with the selection of the value of the view object using the index you have found as

    If (valueChangeEvent.getNewValue ()! = null)
    {
    selectIndex = int ((Integer) valueChangeEvent.getNewValue ()) .intValue ();
    Line selectedRow = AMImpl.getVO1 () .getRowAtRangeIndex (selectIndex);
    If (selectedRow! = null)
    {
    selectValue = (String) selectedRow.getAttribute ("RtNo");
    }
    }

    where AMImpl is the object of the application module class.

    Kind regards
    Vikram

  • Refresh of Page partial update of form before the data control returns the new value

    Hello

    I have a set of paintings of master detail based on a single data source (Session Bean encapsulating a web service call). The high-level table (t1) shows data of opportunity, as the low level (t2) poster contacts for a special occasion. When the opportunity is selected in t1, the contacts associated with this opportunity appear in t2. These tables of work as you wish.

    I have a read only form (form of the Panel layout) based on a different data control (supported by a Session Bean that calls a LinkedIn API and a table of database using EJB3 entities). LinkedIn Session Bean method takes a parameter which I get from the current row in t2. (#{bindings.relatedContact.currentRow.dataProvider.id}) I put the PartialTriggers as 't2' on the form.

    When the page is loaded for the first time, the first line (line A) from table t2 is selected and the display shows the data associated with this line. If I select another line (line B), the Session Bean is called with the value of the id of the newly selected row, but the display will show the associated data from line A. Thereafter, whenever I select a row in t2, bean is called with the new value, but the form displays the data from the selected line previously.

    I guess what happens is that the form is refreshed (using stale data in the data control), and then the call to the session bean is made. I checked using thread and print statements. Sleep() in the bean.

    Is this a correct behavior and how can I make sure that the call to the bean occurs before the form is updated?

    I use JDeveloper version 11.1.2.2.0

    Thank you
    Michael

    Hello

    as answered on StackOverflow, the trick is to set the refresh option on the iterator (s) to the second access WS (table 2) of PageDef on ifNeeded. The default setting is delayed, which in your case is not optimal because refresh occurs during rendering response, which is too late for the access of WS. Try "ifNeeded.

    Frank

  • dialog box closed = > refresh LOV = > set the new value

    Hello

    I'm really struggling with the following problem. I want my users to pick up existing customers or create a new if it does not exist. So I have a form (P1), a form is LOV with existing customers and a "Create new customer" button next to the LOV that calls the form of the modal dialog box (P2), where the new customer can be added.

    In the P2 process customer's line is an option to return an item, so I return it to P2_CUSTOMER_ID (which is my primary key element). On P1, I created the dynamic action:

    Event: Dialog closed

    Selection type: button

    Button: AddCompany

    and there are 2 real actions.

    (1) item discount P1_CUSTOMERS_LOV

    (2) set

    Type: Dialog box return

    RMA: P2_CUSTOMER_ID

    Affected items = > product (s): P1_CUSTOMERS_LOV

    LOV customers is refreshed correctly but the value is not set. What is even more surprising, it's that if I "insert" another action between these two (run code alert javascript ("added customer");), the new value is set correctly as planned.

    I really have no idea of what Miss me, and any help would be highly appreciated.

    Kind regards

    Pavel

    Pavel,

    I could make it work with a Select list. See once more your example. There is a dynamic onload action using

    $("#P2_CUSTOMER_ID").bind ("apexafterrefresh", function() {}

    $ ('#P2_CUSTOMER_ID') .val ($ (' #P2_CUSTOMER_ID_H ') .val ());

    });

    then, who is only triggered if the refresh of the selection list is completed.

    Denes Kubicek

  • Get the old value and the new value based on the date

    Hello

    I have a table called list created below with the rest of the insert statements.

    CREATE TABLE ROSTER
    (
    NUMBER OF ROSTER_EMPLOYEE_DEF_ID
    NUMBER OF EMPLOYE_ID
    NUMBER OF DEFINITION_REGION_CODE
    NUMBER OF DEFINITION_DISTRICT_CODE
    NUMBER OF DEFINITION_TERRITORY_CODE
    START_DATE DATE,
    END_DATE DATE
    )



    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (1,299,222,333,444, 'JUNE 1, 2011', 30 JUNE 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (2,299,223,334,445, "1 JULY 2011', JULY 20, 2011" "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (3,299,224,335,446, 'AUGUST 1, 2011', AUGUST 30, 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (4,300,500,400,300, 'JUNE 1, 2011', JUNE 20, 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (5,300,501,401,301, "1 JULY 2011', JULY 20, 2011" "")


    In the table above we have columns like

    EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE

    The result I'm looking for the table above is based on the employe_id OF start_date AND end_date

    I need to get the OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_CODE
    Similarly, OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_REGION_CODE
    and OLD_DEFINITION_TERRITORY_CODE and the NEW_DEFINITION_TERRITORY_CODE


    I need to get a row of data for each employee saying old value and the new value

    for the employee 299 there are 3 records he puts the new record which is the latest date is to say beginning August 1, 2011 and end date of recordings old 30 August 2011
    beginning July 1, 2011 and July 20, 2011


    For the data in the table above, I need to get the data as below


    EMPLOYE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_CODE OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE START_DATE END_DATE
    299 223 224 334 335 20 JULY 11 30 AUG 11
    300 500 501 400 401 20 JUNE 11 JULY 20, 11


    Please suggest me to get the result above, based on the data. Please let me know if my messages are not clear


    Thank you
    Sudhir
    SELECT  EMPLOYEE_ID,
            OLD_DEFINITION_REGION_CODE,
            NEW_DEFINITION_REGION_CODE,
            OLD_DEFINITION_DISTRICT_CODE,
            NEW_DEFINITION_DISTRICT_CODE,
            OLD_DEFINITION_TERRITORY_CODE,
            NEW_DEFINITION_TERRITORY_CODE,
            START_DATE,
            END_DATE
      FROM  (
             SELECT  EMPLOYEE_ID,
                     ROW_NUMBER() OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE DESC) RN,
                     LAG(DEFINITION_REGION_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_REGION_CODE,
                     DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE,
                     LAG(DEFINITION_DISTRICT_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_DISTRICT_CODE,
                     DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE,
                     LAG(DEFINITION_TERRITORY_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_TERRITORY_CODE,
                     DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE,
                     LAG(END_DATE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) START_DATE,
                     END_DATE
               FROM  ROSTER
            )
      WHERE RN = 1
    /
    
    EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE OLD_DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE OLD_DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE START_DAT END_DATE
    ----------- -------------------------- -------------------------- ---------------------------- ---------------------------- ----------------------------- ----------------------------- --------- ---------
            299                        223                        224                          334                          335                           445                           446 20-JUL-11 30-AUG-11
            300                        500                        501                          400                          401                           300                           301 20-JUN-11 20-JUL-11
    
    SQL>  
    

    SY.

  • Failed to install the new flashplayer from adobe

    Original title:

    Adobe flash player

    I'm still not able to install the new flashplayer from adobe, message reads, close glplayer and try again, Please HELP ME

    Flash Player

    First of all, try to enable Active Scripting in the areas of Sites Internet Options, security settings, trust.

    You should also add a corrupted on.

    Click Start, type: Internet Options

    Press enter

    Select the "Advanced" tab

    Under reset Internet Explorer settings, click "reset".

    This should restore the Internet Explorer default settings.

    Then reinstall Flash Player

    http://get.Adobe.com/flashplayer/

    ----------

    Flash Player

    Troubleshoot installation of Flash Player for Windows

    http://kb2.Adobe.com/CPS/191/tn_19166.html

    Troubleshooting player stability and performance

    http://blogs.Adobe.com/JD/2010/02/troubleshooting_player_stabili.html

    Uninstaller

    http://kb2.Adobe.com/CPS/141/tn_14157.html

    Flash Player Support Forum

    http://forums.Adobe.com/community/webplayers/flash_player

  • Restore the default value from the drop-down list

    Hyperion Inreatctive reports.

    I have an embedded in a dashboard report.  I drag the lists that filter the report.  Filter feed results and it works fine.

    I want to put a command button on the dashboard that restores the default values from the dropdown lists.  I have a selection in each drop-down menu, 'all '.  "All" is the default value.

    For example, for the year

    drop_Year

    for the region:

    drop_Region

    What command should I put on the command button that any value is displayed in the drop-down lists of this command, restore it to "all"?


    Watch the Select() method

    w

  • After changing the default threshlod in the user interface, where it stores the new value?

    After I changed the value of the threshold warning/cirtical metric, I noticed there was a 'TARGET_TYPE' _ 'targetname '. XML generated in forlder $AGENT_HOME/sysman/emd/collection. It assumes that the registered here threshold has priority over that of collection.xml in $AGENT_HOME/sysman/admin/default_collection, right? I'm very curious, is if the new threshold is also recorded in some tables, the agent generates the 'TARGET_TYPE' _ 'targetname '. XML after reading the new value? If it is, could someone offer me the East?

    Thanks in advance!


    Thank you
    Satine

    The default collection file supplied with the plug-in is the basis of how the collection for the target type agent. If the user makes changes through the user interface, the agent record in a specific collection of target instance file that selectively replaces the default file in the collection.

    Data collection should be TARGET_METRIC_COLLECTIONS view of $ MGMT.

  • Can I use the old bluetooth keyboard from Apple with the new iPad from Apple pro?

    Can I use my old bluetooth keyboard from Apple with the new iPad from Apple pro?

    When I asked the same question on the Apple Store, they said yes. You need to try to be sure.

  • I just downloaded a version of EVALUATION of MapPoint 2013 demographic details resemble MapPoint 2007... the trial version not have the new data from the 2010 Census?

    I just downloaded a version of EVALUATION of MapPoint 2013 demographic details resemble MapPoint 2007... the trial version not have the new data from the 2010 Census?

    Hello

    The question you have posted is related to Microsoft MapPoint and would be best suited to:

    Technical support of Microsoft MapPoint

    http://www.Microsoft.com/MapPoint/en-us/support.aspx

    Support for MapPoint, streets & trips and Highway

    http://support.Microsoft.com/ph/851

  • How to compare the new values with the old values in triggers.

    Dear all,

    Please tell me how to compare the new values with the old values in triggers.

    Hi, the employee example is in the document. You'd better read yourself.

    CREATE OR REPLACE TRIGGER Print_salary_changes
      BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab
      FOR EACH ROW
    WHEN (new.Empno > 0)
    DECLARE
        sal_diff number;
    BEGIN
        sal_diff  := :new.sal  - :old.sal;
        dbms_output.put('Old salary: ' || :old.sal);
        dbms_output.put('  New salary: ' || :new.sal);
        dbms_output.put_line('  Difference ' || sal_diff);
    END;
    /
    
  • How to select the default value for a choice of selection when page.jsff load

    Hello everyone, I am newbie have little problem

    I have problem with soc (selectOneChoice)
    in this case I ' to select the default value of af: SelectOneChoice (select first selectItem) when the page is finished loading

    < af:selectOneChoice label = "" Jenny Bahan: "id = 'soc1'"
    autoSubmit = 'true '.
    valueChangeListener = "#{WHStockSetReleaseBean.cekJenisBahan} '"
    Binding = "#{WHStockSetReleaseBean.v_jenisBahan}" >
    * < af:selectItem label = "GBB" value = "GBB" id = "si2" / > * = > i'want to select this value for the default (select first selectItem)
    < af:selectItem label = "GBP" value = "GBP" id = "si1" / >
    < / af:selectOneChoice >

    If someone help me to solve this problem

    THX
    agungdmt

    Hello

    try to set the attribute value to af:selectOneChoice like that.

    
    

    Kind regards
    Sicard.

  • Store the new values in the table in the new row so that the 'old' remains in the previous lines

    Hello

    I am a student of genius embedded. I did a VI where I change the values of digital controls, and it saves it as a table.
    I want to store the pair of new values in the new row of this table.
    I have attached a VI where I can change the values of numeric control, as well as the number of lines from another control. But when I change the values, all values in the output table change including values in the previous row. I want these lines to be unchanged and that new line to update.

    Need help.

    If I understand correctly, you want to always 4 models. If so a 2D table will do the trick (see annex VI), otherwise crossrulz' solution should work.

  • List of field values - value blank or select the new entery (creation).

    Hello

    I created an application for employees of the staff:

    I have a list of values that fills the names of employees, based on a table (the table employees

    The field is called EMP_REPORTS_TO (which is the employee)

    When I create a new employee, the field is already filled with a name.

    Q: How can I change is therefore the field said to select or is null (empty) when creating/adding a new employee

    Thanks in advance.

    KP

    Hello

    a4da0ea0-90f7-4631-A736-144c3a8a5e31 wrote:

    Please change your user ID to something meaningful. Reference: Video tutorial how to change username available

    I created an application for employees of the staff:

    I have a list of values that fills the names of employees, based on a table (the table employees

    The field is called EMP_REPORTS_TO (which is the employee)

    When I create a new employee, the field is already filled with a name.

    Q: How can I change is therefore the field said to select or is null (empty) when creating/adding a new employee

    Thanks in advance.

    Go to the field attributes EMP_REPORTS_TO-> section of the list of values and set:

    • Display Null value-> yes
    • Null-> - Select value-

    How do you access the form page? I guess that the click of a button with the button action the value-> to navigate to the Page of this Application.

    If Yes indicate your number of page in the section to clear the Cache, so that it clears the session state from the new entry form.

    Kind regards

    Kiran

  • iTunes sorts only the new songs from the album artist; Cannot select multiple artists

    I had this problem for awhile now.  Whenever I have add a new song to my library, it will sort as a new artist, even if I already have this artist.  For example, I'll add a new Bayside song to my library, and despite the fact that I already have two albums of Bayside, the new song will sort itself separately from him, leaving me with two Baysides.  The only way to fix it is to add the album artist in both the novel and the stuff I already had.  It's incredibly frustrating, especially since iTunes allow me to select several artists both in the artist's view (although I can select several songs and albums - this seems to be a problem only when the view is the sidebar, as in the views of artist, Genre and composer).

    Help with fixing a problem (preferably both, although) it would be appreciated.

    I am currently using iTunes 12.3.2.

    It's a response of turingtest2 to a very similar to your question.  Maybe this will help.

    12 iTunes keeps having the same artist twice in the artist column

    Using the view songs grab all the tracks by an artist of the album given that you are having problems with and then read the information. Tab sort add set Album artist & artist album, X, click OK, and then return to . If you synchronize your content on a non - iOS such as classical iPod device, then you must also make sure artist is constant in the whole album. I propose generally invited and artists featured in the names of individual songs.

Maybe you are looking for

  • How cofirm what version of firefox using IM

    I downloaded the upgrade to 3.6 and don't know if it worked

  • Computer hard locks after the notation in the world of Warcraft character select screen

    My computer hard locks after installing the new patch for world of warcraft. I followed all the steps to address this problem with undesirable results. I have reinstalled the world of warcraft, patched successfully, but when connecting, I hard-lock a

  • 001 own EFS 17-85 lens contacts,

    The goal of give me problems in the range of 17 to 35mm. It sews higher than work OK. I tried cleaning the contacts and a web site, setting the shutter speed to max. Who has worked for about 10 shots and now doesn't work at all. It is a camera repair

  • Can I delete records 9 k GSC + files on my PC?

    I run a PC with XP SP3 update permanently up-to-date.  It works very well.I noticed a folder root of drive C: named GSC, which contains more than 9 k (0.6 GB) of files and files dated a few years and all appointed with numeric values.  I can't find t

  • What happened to scan for the HP 3050 software has?

    After analysis successfully for 2 years of my HP 3050 has for my Macbook Pro I got a message 'the software for this printer is currently unavailable' on my laptop today when I tried to scan my laptop.  And when I press the "Scan" button on the printe