Select records based on the value

Hello

I have a table with 3 fields,
WITH t1 AS(SELECT 'P1' po_number,'R1' route_id,1900 route_cost FROM dual
UNION ALL SELECT 'P1','R2',2300 FROM dual
UNION ALL SELECT 'P1','R3',1100 FROM dual
UNION ALL SELECT 'P2','R7',1200 FROM dual
UNION ALL SELECT 'P2','R8',4500 FROM dual)
SELECT * FROM T1

PO_NUMBER     ROUTE_ID     ROUTE_COST
P1     R1     1900
P1     R2     2300
P1     R3     1100
P2     R7    1200
P2     R8    4500
and I want to choose single route_id for a po_number where the cost is high
and my output should be
PO_NUMBER     ROUTE_ID     ROUTE_COST
P1     R2     2300
P2     R8     4500
Thank you
San

Published by: sandeep9 on April 9, 2011 04:22
WITH t1 AS(
           SELECT 'P1' po_number,'R1' route_id,1900 route_cost FROM dual UNION ALL
           SELECT 'P1','R2',2300 FROM dual UNION ALL
           SELECT 'P1','R3',1100 FROM dual UNION ALL
           SELECT 'P2','R7',1200 FROM dual UNION ALL
           SELECT 'P2','R8',4500 FROM dual
          )
SELECT  po_number,
        max(route_id) keep(dense_rank last order by route_cost) route_id,
        max(route_cost) route_cost
  FROM  T1
  GROUP BY po_number
/

PO RO ROUTE_COST
-- -- ----------
P1 R2       2300
P2 R8       4500

SQL> 

SY.

Tags: Database

Similar Questions

  • Poller DB to select records based on the timestamp

    Hi all

    I want select records from the coloumn timestamp where the timestamp is older than an hour. Is it possible to do this through poller db? I tried but unable to pass the dynamic value (currently - 1 hr)

    Thanks in advance!

    Eventually create a view based on the timestamp and singled out the dbpoller view.

  • Need to set the attribute of the current record based on the value of the next record

    With the help of forms 6, I have a form that displays the list of folders. There may be multiple records with the same ID, but with different expiration dates. I need set attributes for hilite only the record with the latest expiration date. The current list points of interest reviews of future expiration dates - but we found that, sometimes, the subscription is renewed before the expiration date has been reached, causing two records with the same ID with expiry dates in the future.

    I can (and do) sort the records by date of expiry and the identification for the record with the latest expiration date is always the last to this ID, so what I want to do is to check the next record to see whether or not it has a different ID. If the current record is the last expiration date, & must be hilited. Because I might want to hilite the current record, I can't simply navigate to another record, according to the description I found, what makes the next_record builtin. Anyone know how I can check for a value in the next record without making the current record?

    Thank you.

    What I would do:

    -Create a DB view based on your table and including the function call DRIVE as a separate column.
    -Base that block you on this point of view
    -If the block is modifiable, set the DML target for the block to your database table.

  • Select records based on the monthly anniversary date

    Hello

    I have a table with a field of date_added and I want to select records from monthly birthday of this field.

    for example. ID, Date_added
    1, DECEMBER 10, 2012
    2, 11 NOVEMBER 2012
    3, 10 MARCH 2012
    4, FEBRUARY 28, 2012
    5, 30 DECEMBER 2012

    So for January 10, 2013, I would like to return the documents 1 and 3 only

    I started watching the extract function, but this little falls down to the records at the end of the month. For example, on 28 February, I also include records where 29, 30 or 31 is the day of date_added. So, in the above table, I won't return documents 4 and 5, but retrieves only returns 4.

    Is there a simple function to make the request of birthday this month - have I missed something very obvious? Or I have to write a query to explicitly dates at the end of the month? So far I have not found a reasonable solution!

    I use 11g

    Thank you

    user11259857 wrote:
    Hi Al,.

    No I don't think that there is a flaw. For example, the 30 Jan is not the last day of the month, but is June 30. Thus, on 30 January I want only to interrogate all the dates falling on the 30th - 28 February, after already being interrogated on the 28 Jan. However, on 30 June, I would query the 30th of each month, as well as the 31 January, March, may, July, Aug, Oct, dec. February is a special case, being both shorter and a leap year

    Thank you

    Richard

    Hi Richard,

    so, we can assume that your needs are:

    If the day is the last day of that month, interview the day of the other months being > = day of the current month.

    That is to say:

    Jan-30 = query only 30 other months
    Jan-31 = query only 31 of the other months

    Feb-28 (non-leap years) = question 28, 29, 30 and 31 other months
    29 February (leap year) = query 29,30,31 to other months

    Mar-30 = query only 30 other months
    Apr-30 = query 30 and 31 other months

    This hypothesis is correct?

    If so, then something like this should work:

    WITH mydates(id, date_added) AS
    (
       SELECT 1, TO_DATE('10-DEC-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 2, TO_DATE('11-NOV-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 3, TO_DATE('10-MAR-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 4, TO_DATE('28-FEB-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 5, TO_DATE('30-DEC-2012', 'DD-MON-YYYY') FROM DUAL
    )
    SELECT id, date_added
      FROM mydates
     WHERE (:input_date = LAST_DAY(:input_date) AND TO_CHAR(:input_date,'DD') <= TO_CHAR(date_added, 'DD'))
        OR TO_CHAR(:input_date,'DD') = TO_CHAR(date_added, 'DD');
    
    with input_date = 28/02/2013
    
    id   date_added
    4    28/02/2012
    5    30/12/2012
    

    Kind regards.
    Al

    Published by: Alberto Faenza on 10 January 2013 15:21
    Added example

  • Query - remove duplicate records, based on the value of a field

    Hello


    Please view the information below,
    How to delete records when his number 0
    AND these records (name) repeat with count > 0
    existing data
    
     name                       loc                            count
    ------------------------------------------------------------------------
    
    aaa          a1          10
    aaa          a1          0
    bbb          b1          0
    ccc          c1          0
    dcc          d1          11
    dcc          d1          0
    
    required output
    
    ---------
    
    
     name                       loc                            count
    ------------------------------------------------------------------------
    
    aaa          a1          10
    bbb          b1          0
    ccc          c1          0
    dcc          d1          11
    
    
    
    remove these records -
    
    -----------
    
    aaa          a1          0
    dcc          d1          0
    Thank you.

    I guess that loc always matches the name. Thus, to find the lines of stay is just a simple group of

    with data as(
    select 'aaa' name,'a1' loc,10 count from dual union all
    select 'aaa','a1',0 from dual union all
    select 'bbb','b1',0 from dual union all
    select 'ccc','c1',0 from dual union all
    select 'dcc','d1',11 from dual union all
    select 'dcc','d1',0 from dual )
    
    select
      name
    , loc
    , max(count) cnt
    from data
    group by
      name
    , loc
    order by
      name
    , loc
    
    NAME     LOC     CNT
    aaa     a1     10
    bbb     b1     0
    ccc     c1     0
    dcc     d1     11
    

    to find that the other is just a minus

    with data as(
    select 'aaa' name,'a1' loc,10 count from dual union all
    select 'aaa','a1',0 from dual union all
    select 'bbb','b1',0 from dual union all
    select 'ccc','c1',0 from dual union all
    select 'dcc','d1',11 from dual union all
    select 'dcc','d1',0 from dual )
    
    select name,loc,count from data
    minus
    select
      name
    , loc
    , max(count) cnt
    from data
    group by
      name
    , loc
    order by
      name
    , loc
    
    NAME     LOC     COUNT
    aaa     a1     0
    dcc     d1     0
    

    would be a delete

    delete from data
    where
    (name,loc,count)
    in
    (select name,loc,count from data
    minus ..
    

    concerning

  • A drop-down list can do the calculation based on the value selected in a drop down list?

    Form Acrobat X Pro Adobe

    Can I have a drop down list create a calculation based on the value selected in the menu drop-down?

    We have a set lunch and want the user to choose to be "A lunch', 'Lunch B'"C Lunch"or"just the milk. "

    It is for each of the 5 days of the week. There are therefore 5 drop downs, which have all the same 4 above choice.

    If the user chooses among the 3 lunches and then put $2.00 in the total box at the end of the line. If 'Just the milk' may put 0.50 in the box.

    The total area at the end of the line must keep a record of all 5 days and give a total.

    So if someone chooses lunch A LUN, sea and Sun and just milk for Tuesday and Thursday and then the total for this week must be $7,00

    Is it possible by using code or something?

    I did it in Excel, but we need it is an Adobe pdf file.

    TIA

    OK the total box has a 10 all the time to make it look like $ 2.00 for

    everything.

    Before even that I chose something there are 10 in the box.

    I am a newbie to Adobe scripting Total used VB/A .NET etc ' 1980

    However.

    Can you do any debugging in code?

    Initialize the sum

    var sum = 0;

    Make a loop on the drop-down list boxes and add the cost of the invoice sum

    for (var i = 1; i)< 6;="" i="" +="1)">

    Sum += getField("Week1Day"_+_i).value == 'just milk? 0.50: 2,00;

    }

    Set this field to the amount

    Event.Value = sum;

  • Delete in the database based on the values of the multiple selection list

    Hello

    I have a selectlist in Apex and a function in the database to make a deletion based on the value selected in the selection list.
    FUNCTION delete_batch (v_batch VARCHAR2) RETURN VARCHAR2
    IS
    BEGIN
    IF v_batch like 'M%'
    THEN
       RETURN ('A monthrun cannot be deleted');
    ELSE
       DELETE FROM so_disco_pa
       WHERE  batch = v_batch
       ;
       DELETE FROM so_batch_pa
       WHERE  batch = v_batch
       ;
       COMMIT;
       RETURN ('Batch '||v_batch||' has been deleted');
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
        RETURN ('Batch could not be deleted');
    END delete_batch;
    The package is called when the user clicks on the button Delete with the rest of the process:
    BEGIN
    DECLARE
    x   varchar2(100);
    BEGIN
    x := pa_control.delete_batch (:P3_BATCH);
    :F105_MESSAGE := x;
    END;
    END;
    Now, I want to change the selectlist for a multiple-selection list to make several batches can be deleted.

    How can I change my procedure and the procedure to remove lots based on the values selected?

    Thank you

    Diana

    dianap says:
    I got this far, but only the first batch selected in the list is being deleted. The other values of selected package are not removed.

    Help please.

    Move the RETURN statement out of your loop.

  • How to create table selectable line or not based on the value of the line

    Hello.

    JDeveloper 11.1.1.2

    Is it possible to make a selectable table row or not based on a value in the line.

    That is to say. lets say that the row contains a Boolean LOCKED = TRUE.
    This line should not be selectable.

    A line whose value LOCKED = FALSE should be selectable.

    / Erik

    Erik,

    No particular reason to disable a selection of lines for a particular line? If I'm an end user, I would be clicking on the same line of thought again and again my mouse does not ;) (call me dumb :)). How do you differentiate this line (using inlineStyle / styleClass) based on the value of line? In addition, you can disable the other buttons when a row with a particular value is selected (so that the user knows that the selected line is not treatable).

    Arun-

  • How to render components based on the value selected in a list of values

    Hello
    I created a form of the ADF. I have a drop down that is a list of values. I want to toggle certain fields based on the values selected in the menu drop-down. Could you please let me know how to do it in the ADF?

    Kind regards
    Murielle

    Hello

    It should work. It is important to note that in case you use a component selectOneChoice for category then the value returned by #{bindings. Category.inputValue}
    is the index of the selected value in the list and not the value auto. To get the value, you must use ' #{bindings. " Category.attributeValue}"in the disabled state.

    If the problem is no display of code in your page to take a look.

    Gabriel.

  • Selective display of a report based on the value of a Variable of presentation

    Hello

    Is it possible to selectively display a report on a dashboard page based on the value of a variable presentation.

    I have 5 reports that are part of the same page that has a page with 5 options-level prompt.

    According to the option selected in the command prompt that the value is stored in a variable of the presentation, I need only 4 reports to view at any time (ie 1 report should NOT be directed).

    Example: -.

    When Option 1 is selected 1,2,3,4 reports must be posted
    When Option 2 is selected 2,3,4,5 reports must be posted


    Thanks in advance

    Hello

    Search this Guided Navigation forum. In this way, you can hide a section on your dashboard based on the results of a report that is "hidden".

    Good luck

    Daan Bakboord

  • dynamically display title based on the value selected in the column picker

    Hi all
    Would it be possible to display the title of the dynamic report based on the value selected in the column picker. Suppose I have two State of the column and region. When I choose the status in the column picker the title of the report will show 'Summary of the situation' when I'll choose the region then the title will change to "summary of the region. Please help me...

    Hello

    Check your mail before I send the entire process with screenshots.

    Concerning

    NGO

  • Fill in fields on a form based on the value of a list? (Dreamweaver CS5)

    Yet once, it has been a while since I've done any work in Dreamweaver. I have two sets of records, rs1 and rs2. Fill a selection area with a dynamic field, rs1. Based on the value of the selection in the list box and use it as a primary key and a database .mdb I want to fill that second record, rs2 and respective fill some additional fields with its dynamic links.

    Assuming that everyone can understand what I so badly stated, with a having a few ideas or, better yet, a few examples?

    Thank you!

    I agree with Nancy that using Access is a bad choice, to answer your question, it seems you want to create a montage cascading down. Dreamweaver is not integrated to manage cascading dropdown lists. You code yourself.

    There are two approaches for cascading drop-down lists:

    • Use Ajax to present a second query to the database when the first drop-down list is selected.
    • Store the values of the dependent drop-down list in a table, and use JavaScript to fill in the options in the first drop-down list is selected.

    This page of examples of cascading dropdowns: example of DropDownList in waterfall | Kendo UI Dropdownlist demo. A Google search for the cascading drop down list will produce other results.

  • Define a transitional EO attribute based on the value of the attribute being questioned or persistent

    How to set the value of an attribute of EO questioned not persistent or not based on the value of another attribute of OS which is persistent and questioned the database?

    Thank you

    I finally made it through the PR and PFR controller (when a record is selected) methods.  It works, but I was looking for a hook in the what the VORow instances are created.  As thecreateInstanceFromResultSet method but at this time the transient attributes do not exist in the result set.

  • Fill a field value based on the value of another field

    Hello
    Could someone tell me what is the problem with the following select statement. For a group of records, trying to fill a field with a value based on the value in another field (problem of status), but the Group of records appears empty just when I put this code in the field.
    Any help would be appreciated
    Thank you


    <? choose:? >
    <? When: IssueStatus = "Open"? >
    <? 1? >
    <? end when? >
    <? otherwise:? >
    <? When: IssueStatus = "closed"? >
    <? 2? >
    <? end when? >
    <? otherwise:? >
    <? When: IssueStatus = "Unresolveable? >
    <? 3? >
    <? end when? >
    <? end otherwise? >
    <? end to choose? >

    Use the following syntax.

    
    
    Display 1
    
    
    Display 2
    
    
    Display 3
    
    
    
  • Need to display negative amounts, amounts positive based on the value of the parameter.

    Hi all

    I have a requirement in rdf as follows:

    I have two or three lines of the SELECT statement. An amount column having both negative and and postivie values.

    Based on the value of the parameter I need to take these records.

    Say, if the value of the parameter = "Credit amount", then I have to choose the records, the amount column value is negative.

    If the value of the parameter = "Debit amounts" then I have to choose the records, which the column value is positive.

    If the parameter Value = "All", then I must take all records, including both positive and negative.

    Please suggest how to achieve this scenario.

    Thank you
    Abdul

    In your where clause to add the following
    and ((& paramètre = "Débit" et montant > 0) or)
    (& parameter = 'Crédit' and the amount<0)>
    (& parameter = 'All'))

    Hope that answers your question
    Sandeep Gandhi
    Independent consultant
    513-325-9026.

Maybe you are looking for

  • Satellite Pro A10: CD rip procedure takes for a long time.

    Toshiba Satellite Pro A10... Tried to rip a CD on my computer. Yesterday, the process was real quick as 10 minutes per cd. Today is a time frustrating per cd! Everyone thinks that the hard drive was missing? Or I'm just something incredibly stupid? W

  • Pavilion G6-1d98dx: BIOS administrator password

  • Equium L350 - BSOD when I upgraded to 4 GB of RAM

    I have a Toshiba Equium L350 (PSLD2E) and I'm running a 64 bit OS and also runs the latest version of the BIOS for the Toshibia and 3 GB of RAM, but when I switch to 4 GB, the machine displays a blue screen.I was wondering if Toshiba will relase a BI

  • I can't find the info bar or install the activeX control

    I'm trying to update microsoft windows, and this happens every time. When I try to right click on where the information bar is supposed to be located, under the address bar, it never shows me "click on Install ActiveX Control". Also, it does not I'm

  • The sticky engine

    I have a very funny bug (?). In the extract which is attached when the condition for both cases structures become TRUE, I am turning off an engine power of 22KW, bit, he wrote to a function of writing DAQMX and goes to the next case. 3 of the 10 time