I want a select statement to return two values, sum of one column and customer number

I have two columns one called invoice_number and the other invoice_amount. I want a select statement to return two columns.... invoice_number and then the sum of the invoice_amount(s) for each unique invoice number.
SELECT sum(invoice_amount) AS Totalinvoice_amount FROM InvoiceTB where invoice_number = 'INV102'
This is where I've started, which returns:
Totalinvoice_amount
500.00
Any help is appreciated.
Please mark my post as helpful or the answer or better yet.... both! :) Thanks!

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
This is minimal polite behavior on SQL forums. 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Howto create 'select statement' that returns first row? (simple table)

    quick question that drives me crazy:
    Say I have the following table:
    ID....car_model....point_A....total
    1........333.............NY..........54
    2........333.............NJ..........42
    3........333.............NH...........63
    4........555.............NJ...........34
    5........555.............PA...........55
    I would like to create a select statement that return car_model which the starting point is NJ - in this example it's only 555.
    thanks for any tips

    fair enough.
    the problem is this: given the table below, I need to create a report that reflects car rentals from specific location. you can rent a car from different locations; a car has a starting point (like a flight itinerary) so consider this:
    Mark rent a car with the following itinerary:
    NY--> NJ
    NJ--> PA
    PA-->FL
    FL-->LA
    the end user would like to see all car that were rented between X and Y and start point was NJ, so in the example above, the starting point is NY so it doesn't match the end users' criteria.
    The table is organized in the following manner: ID....car_model....point_A....total
    * I don't know whey the someone choose point_A as a column description as it just suppose to be 'location'
    so, back to my first example:
    ID....car_model....point_A....total
    1........333.............NY..........54
    2........333.............NJ..........42
    3........333.............NH...........63
    4........555.............NJ...........34
    5........555.............PA...........55
    if I do this:
    Select car_model from myTable where point_A='NJ'
    the return result will be 333 and 555 but that is in correct because 333 starting point is NY.
    I hope I provided enough information, thanks

  • Return two values from autosuggest

    hi i have inputtext with autosuggest,i what to return two values when i select the values for example if i select cityname i must return cityname and citypostacode for that city.this is how i did my inputtext autosuggest
    <af:inputText label="#{bindings.Cityname.hints.label}" columns="20"
                                            maximumLength="#{bindings.Cityname.hints.precision}"
                                            id="itc4" simple="true"
                                          value="#{pageFlowScope.orgDetailsBean.addressBean.city}"
                                          partialTriggers="it19" autoSubmit="true"
                                          shortDesc="Enter City Name Or Click Refresh To re-enter City Name">
                                <af:autoSuggestBehavior suggestedItems="#{pageFlowScope.addressbean.oncitySuggest}"/>
                            <af:autoSuggestBehavior/>
                          </af:inputText>
        public List oncitySuggest(String searchCityName) {
        ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
            searchCityName = searchCityName.toUpperCase();
        System.out.println(searchCityName);
        //get access to the binding context and binding container at runtime
        BindingContext bctx = BindingContext.getCurrent();
        BindingContainer bindings = bctx.getCurrentBindingsEntry();
        //set the bind variable value that is used to filter the View Object
        //query of the suggest list. The View Object instance has a View
        //Criteria assigned
        OperationBinding setVariable = (OperationBinding) bindings.get("setBind_city");
        setVariable.getParamsMap().put("value", searchCityName);
        setVariable.execute();
        //the data in the suggest list is queried by a tree binding.
        JUCtrlHierBinding hierBinding = (JUCtrlHierBinding) bindings.get("CityViewLOV1");
        //re-query the list based on the new bind variable values
        hierBinding.executeQuery();
        //The rangeSet, the list of queries entries, is of type
        //JUCtrlValueBndingRef.
        List<JUCtrlValueBindingRef> displayDataList = hierBinding.getRangeSet();
        for (JUCtrlValueBindingRef displayData : displayDataList){
        Row rw = displayData.getRow();
        //populate the SelectItem list
        selectItems.add(new SelectItem(
        (String)rw.getAttribute("Cityname"),
        (String)rw.getAttribute("Boxcode"),
        (String)rw.getAttribute("Citycode")));
        return selectItems;
        }

    KK-$$ wrote:
    Now I need 1 more column say, flag something like:
    open o_ref_cursor for select function_name( 2345) Emp_no ,  function_name_2 ( 2345) flag from table1 where x = y;But I don't want to define a new function function_name_2 to get flag value. Because emp_no and flag are both queried from the same table.
    So, Can you tell me how can I make 'function_name' to return two values using appropriate data-type ( or user defined data type?)?Your example could be solved like this (since it is in pl/sql):
    v_emp_no := function_name( 2345);
    v_flag := function_name_2 ( 2345);
    open o_ref_cursor for select v_emp_no Emp_no , v_flag flag from table1 where x = y;But I guess the example was still too simplicistic.

  • How do I return two values from a stored procedure into an "Execute SQL Task" within SQL Server 2008 R2

    Hi,
    How do I return two values from a
    stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
    Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
    Something like ?
    CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
    @intPeriod INT,
    @strPeriod_Length NVARCHAR(1),
    @dtStart NVARCHAR(8) OUTPUT,
    @dtEnd NVARCHAR(8) OUTPUT
    AS
    then within the SSIS component; -
    Kind Regards,
    Kieran. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
    Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
    Add a script task to check ssis variables values using,
    Msgbox(Dts.Variables("User::strExtractStartDate").Value)
    Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
    Regards, RSingh

  • I Need to Return Two values or more from Function, Is this possible?

    Below is the offending query, I am trying to pass v_bu and v_po to this function, and after validations then return v_count and v_action is this possible in a function? I am having problem returning two values.
    see below code
    function po_edi_func(v_bu purchase_order.business_unit_id%type,
         v_po purchase_order.purchase_order_number%type)
         return number as pragma autonomous_transaction;
         v_count               number;
         v_ctdel               number;
         v_action          varchar2(1);
    begin
    select count(*)
    into v_count
    from sewn.purchase_order
    where business_unit_id=v_bu
    and purchase_order_number =v_po;
    if v_count > 0 then
         select count(*)
         into v_ctdel
         from sewn.purchase_order
         where business_unit_id=v_bu
    and purchase_order_number =v_po
         and purc_orde_status = 1;
         if v_count <> v_ctdel then -- ALl PO's Cancelled--
         v_action := 'U'; -- - NOT ALL PO DELETED --
         else
         v_action := 'D'; -- DELETED ALL PO--
         end if;
    else
         v_action := 'I';-- New PO INSERT--
    end if;
    commit;
    return v_count;
    end;

    Paul,
    This is becoming a nightmare to me, can you look at the below and tell me where I am having a problem
    This is the Function below
    CREATE OR REPLACE function po_edi_func(v_bu sewn.purchase_order.business_unit_id%type,
         v_po sewn.purchase_order.purchase_order_number%type,v_action_out OUT VARCHAR2)
         return number as pragma autonomous_transaction;
         v_count               number;
         v_ctdel               number;
         v_action          varchar2(1);
    begin
    select count(*)
    into v_count
    from sewn.purchase_order
    where business_unit_id=v_bu
    and purchase_order_number =v_po;
    if v_count > 0 then
         select count(*)
         into v_ctdel
         from sewn.purchase_order
         where business_unit_id=v_bu
    and purchase_order_number =v_po
         and purc_orde_status = 1;
         if v_count <> v_ctdel then -- ALl PO's Cancelled--
         v_action := 'U'; -- - NOT ALL PO DELETED --
         else
         v_action := 'D'; -- DELETED ALL PO--
         end if;
    else
         v_action := 'I';-- New PO INSERT--
    end if;
    commit;
    v_action_out := (lpad(v_count,8,'0')||lpad(v_action,1,' '));
    return v_action_out;
    end;
    and this is how I am calling it from my trigger which has to pass the v_bu and v_po values to be used in extracting data and returning the records
    see below
    if po_edi_func(v_bu,v_po) <> '' then;
    v_count:= (substr(v_action,1,8));
    v_action := substr(v_actione,9,1);
    else
    v_count:=0;
    v_action := 'I';
    end if;
    I need the extracted values of v_count and v_action for my app to reset some values

  • HT1660 I have two iTunes libraries on two different pc's (one windows and one Mac).  Can I consolidate these on an external hard drive?

    I have two iTunes libraries on two different pc's (one windows and one Mac).  Can I consolidate these on an external hard drive?

    I'm sorry I just saw the last post. I had two users on my hard drive, one for me and one for my daughter, but I am not sure what you mean by partioning my external????? I have heard the term before, but don't know how to do it. I am having serious crashing issues with this computer and believe I really need to do a clean install. I just want to make sure everything for both ipods is safe (is???? I think so, everything is......I hate when the English language does this to me!)

  • Hi, I have a large number of products in one column and prices of the products in another. Most prices are different. I want to know if it is possible to increase all of the prices by 5% or 10% etc. Hope someone can help. From Stiffy

    Hi, This is my first time I hope someone can help.
    I am working with numbers and I have a large number of products in one column and the relevent prices in another. All the prices are different and I want to increase the price of everything by 5% or 10% etc. Is this possible?
    Thanks in advance
    Stiffy123

    Ad a new, temporary column (or one you can hide when not using). Let's say the current Prices are in column C and the new column is D.
    you can inflate the prices in column C by 5% by entering the formula in the first cell of column D as:
    =C2*105%
    likes this:
    to fill down, select D2, then copy, then select the D3 thru the end of the column, then paste.  Now select C2 thru the end of column C, now paste over the existing values using the menu item "Edit > Paste Values"
    you can now hide column D until you need to use it again.

  • Two iPhoto '08 Libraries, One External and One Internal...

    Hello,
    I have Two iPhoto '08 Libraries, One External and One Internal. I moved my original iPhoto library to my external HD and all was good. Now about six months later I am noticing that I have two libraries, the external one is 15.8 gigs and the internal one is 17.66 gigs. Can I merge these and how or are one of these an older version of the library that I could delete? Any assistance would be great!
    Thanks,
    Pete

    Pete
    Welcome to the Apple user discussion forums
    are one of these an older version of the library that I could delete?
    Sorry - these are user forums - not physic users forum
    my best guess is that you never directed iPhoto to use the external library and that is is a back up of your old library and that your internal library is the complete library - but that is just a guess
    To switch libraries and look at the launch iPhoto while depressing the option (alt) key and use the select library function - once you figure out what you have you can delete the old or or use iPhoto library manager - http://www.fatcatsoftware.com/iplm/ - to move photos between them
    LN

  • Can you sync two 4S iPhones to one PC and iTunes account?

    Can you sync two 4S iPhones to one PC and iTunes account?

    No you don't. You log into iTunes with your Apple ID but you can use one Apple ID for iTunes and a different Apple ID for iCloud. On your device go:
    Settings > iCloud > Delete Account and sign in with a new Apple ID
    This will only change the Apple ID for iCloud and both devices will continue to download apps and backup to the shared iTunes account.

  • Can you have two seperate acounts on one MAC and if so how do you do it?

    Can you have two seperate acounts on one MAC and if so how do you do it?

    Look at Method One in this document:  How to use multiple iPods, iPads, or iPhones with one computer, http://support.apple.com/kb/HT1495

  • Two-step verification needs one SMS capable phone number. As I am a Bangladeshi how can I send phone number.pl help.

    Two-step verification needs one SMS capable phone number. Bangladesh is not listed country. How can I receive message my phone.

    2-step verification is not available in Bangladesh as yet.

  • SELECT statement not returning NULL records

    I have the following SELECT statement:
    SELECT *
    FROM RPT_DS1_CNT_CAT
    WHERE DUPS_SAME <> 'N/A';
    I also tried:
    SELECT *
    FROM RPT_DS1_CNT_CAT
    WHERE DUPS_SAME != 'N/A';
    Same results - There ARE Null DUPS_SAME values
    which are not being selected. I get NO results.
    When I execute this, I do get NULL values.
    SELECT *
    FROM RPT_DS1_CNT_CAT
    WHERE DUPS_SAME IS NULL;
    How can I ensure that I get all non - 'N/A' records
    if it won't pick up the nulls? Is there a function
    I can use or a different wording? I do want to use
    != or <> because there may be other values besides
    'N/A' such as 'YES' or 'NO' and they may be null or
    filled with spaces.

    The expression
    NVL(DUPS_SAME,'') is meaningless. You're saying "If DUPS_SAME is NULL, return the empty string, which is NULL, otherwise return DUPS_SAME." If you're going to use NVL, the string that gets returned if the column is NULL should be non-NULL, i.e.
    NVL(DUPS_SAME,'DUPS_SAME was NULL') Your query should, as others have pointed out, either be
    SELECT *
      FROM rpt_ds1_cnt_cat
    WHERE dups_same <> 'N/A' OR dups_same IS NULLor
    SELECT *
      FROM rpt_ds1_cnt_cat
    WHERE NVL(dups_same, 'DUPS_SAME is NULL') <> 'N/A' Either of these return the same results as your query but they're going to be far clearer for whoever needs to maintain the code. There may be performance differences as well if DUPS_SAME is indexed depending on the data distribution...
    Justin

  • Select statement not returning correct data

    I'm working on an application and I'm having a weird problem. The application connects to an Oracle database, pulls out some data, and does something with it. In the process of testing I've already read and dealt with some rows. On those rows the UPDATE_FLAG field was changed to a N so they wouldn't be selected again.
    I do want to select those rows again, so with SQLPlus I changed the UPDATE_FLAG back to Y. Now here's the strange part. The same select statement run from SQLPlus is returning thoe row I modified, but my application does not.
    Here's the select statement:
    SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%';
    When I run this I get a row back called Brian.
    In my application I do this:
    try
                   Class.forName("oracle.jdbc.driver.OracleDriver");               
                   Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@server:port:sid", "username", "password");
                   Statement st = conn.createStatement();
                   ResultSet rec = st.executeQuery("SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%'");
                   System.out.println("SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%'");
                   while(rec.next())
                        System.out.println(rec.getString("USER_ID"));
                   st.close();
              } catch (Exception e)
                   System.out.println("Error -- " + e.toString());
                   e.printStackTrace();
                }When this runs it doesn't return Brian and there are no exceptions caught. It's like it does not find it.
    Assuming I explained this well enough, anyone have any ideas what the problem could be?
    Thanks,
    James

    I do want to select those rows again, so with SQLPlus I changed the UPDATE_FLAG back to Y. Last time I ran SQLPlus I explicitly had to do a commit after modifications, because it was creating a transaction around the sqlplus session. Of course running a query in that session would work on the modified data rather than the actual data.

  • Funct return two values

    hi,
    can i make a function return more than one value ?
    thanks.
    n/

    Nicholas said he wanted to use this in Forms 6i. Well, 9i Forms does not support stored procedures that return object values, so I doubt very much that6i does.
    I suggest using a procedure with two OUT parameters:
    PROCEDURE get_default_qty (
    p_supp_id IN edtrad.orcrsupp.supp_id%TYPE
    , p_item_no IN edtrad.orcrstit.stit_item_id%TYPE
    , p_ord_id IN edtrad.orcrodet.odet_order_id%TYPE
    , p_qty OUT NUMBER
    , p_val2 OUT VARCHAR2)
    IS
    qty_not_found EXCEPTION;
    PRAGMA EXCEPTION_INIT ( qty_not_found, -20004 );
    v_qty edtrad.orcrdlvd.dlvd_qty_delivrd%TYPE;
    v_val2 VARCHAR2(9);
    CURSOR qty
    IS
    SELECT vd.dlvd_qty_delivrd, "value_two"
    FROM edtrad.orcrdlvd vd,
    edtrad.orcrodet dt
    WHERE vd.dlvd_supp_id = p_supp_id
    AND vd.dlvd_order_id = p_ord_id
    AND dt.odet_item_id = p_item_no
    AND vd.dlvd_order_id = dt.odet_order_id
    AND vd.dlvd_ord_line_no = dt.odet_line_no ;
    BEGIN
    OPEN qty;
    FETCH qty INTO v_qty, v_val2;
    IF ( qty%NOTFOUND ) THEN
    CLOSE qty;
    RAISE qty_not_found;
    END IF;
    CLOSE qty;
    p _qty := v_qty ;
    p _val2 := v_val2;
    END get_default_qty ;
    Notes
    (1) You must fetch a cursor into a matching set of variables (or define a %ROWTYPE).
    (2) set_default_qty is a bad name for this method. set implies value changing. This method doesn't alter anything, it simply retrieves data. Consequently, it should be called get_default_qty.
    Cheers, APC

  • How To? Select List item return 2 values (high and a low)

    Can anyone suggest how to make a select list drop box return 2 values for my query.
    eg:
    Pick from
    Last Week
    Last Month
    Last Year
    return high/lo values of
    5-feb-06 12-feb-06
    01-jan-06 31-jan-06
    01-jan-05 31-dec-06
    Such that my query can refer to it as
    select *
    from tabx
    where dte > :parm_lo
    and dte < :parm_hi
    You get the idea ..

    I haven't tested this at all, so it may not work, but the first thing that springs to mind is not returning the two dates, base it on the current date, i.e. have your select list return something like -
    Last Week - Return 'W'
    Last Month - Return 'M'
    Last Year - Return 'Y'
    then use a query something like -
    SELECT *
      FROM tabx
    WHERE dte >
              CASE v ('ITEM')
                 WHEN 'W'
                    THEN TRUNC (SYSDATE, 'd')
                 WHEN 'M'
                    THEN TRUNC (SYSDATE, 'Mon')
                 WHEN 'Y'
                    THEN TRUNC (SYSDATE, 'yyyy')
                 ELSE dte - 1
              ENDLike I said, completely untested and may not work...you may also have to play around with the boundary values (NLS settings too perhaps).

Maybe you are looking for

  • I installed iTunes on my laptop and can not open it

    I installed iTunes on my Toshiba laptop and it wont let me accept the license agreement. Does anyone have any advise for me? or does anyone know if my laptop not compatible? Thanks

  • What is the data usage for ipad mini on stand by when connected to WIFI?

    We connected 34 ipad mini's for yacht WIFI network that has internet access. Now data usage is 1GB/h higher for the all connections than before. None of the ipad's are used for internet. My question is what is the data usage when ipad is is standby u

  • Upgrade to SAP PI 7.3

    Hi Gurus, We are trying to upgrade from PI 7.0 to PI 7.3 EHP2. We are getting the Java stack alone. How far does it impact the java and abap objects created in PI 7.0. If we upgrade the objects will remain the same or teh objects will be lost. Can yo

  • WRT600N(V1.0) and LG BD390 Blu-Ray player...

    For some reason the LG BD390 is not seeing both access points to the WRT600N. It is only seeing whatever the FIRST one is set to. So if I set the top one to G, it will see it as G and if I set it to N, it will see it as N and will connect fine. Howev

  • How know if the Business Package of ESS, MSS y E-RC are install

    Good Morning, How i know if the Business Package of ESS, MSS y E-RC are install in the system??? In the part of portal and ECC. Kind Regards