Complex MySQL Query, Grouping By Invoice Number and Adding Multiple Values To Insert Into Database

I have a table that looks like the above. I need to be able to update values in a database based on an ioID (the invoice number)
The value I need to add is the hours times the uSalary, however as you will notice above the hours can and well have been added on an ongoing basis. For example:
smarotti has added 4.5 (0.5 + 4.0) hours for the ioID 14190 (last 2 rows) for a total cost of $143.55
So what I need is to have the value $143.55 update the record 14190 (ioID) on a new column (userCost)
So:
the userID - ddevries did 1 hour worth of work at the rate of $23.20 that needs to be update on the record 8026
the userID - kmurtha did 20 (.5 + .25 + 6.5 + .25 + 6.5 + 6) hours worth of work $696 (20 * 34.80) that needs to be update on the record 9462
make sense? anyone have any thoughts on how to go about doing this?
Thanks
Vern

Okay
assuming you add the column to your table the query would look like the below:
UPDATE workers
                INNER JOIN (SELECT
                                                round(SUM(hours*uSalary),1) AS cost,
                                                ioID,
                                                userid
                                        FROM
                                                workers
                                        GROUP BY ioID, userid ) b
                ON workers.ioID = b.ioID
        SET workers.userCost=b.cost
WHERE workers.ioid = b.ioID
AND     workers.userID = b.userID
Or if you would just like to query the data:
SELECT  round(SUM(hours*uSalary),1) AS usercost,ioID,userid
FROM workers
GROUP BY ioID, userid

Similar Messages

  • Report ( invoice number and delivery number)

    Hi
    Is there any report in SAP, which can show invoice number and delivery document number, I know the SAP table, but is SAP standard report available?
    Example:PO: 5500075241, plant abraod delivery number 3510000174 and plant abroad Invoice number 3550000019, we need report which gives Delivery and Invoice no.
    thanks

    No standard reports shows both delivery and billing references in a single report.  You can develop a query in SQVI by table joining VBFA, LIKP and VBRK.
    thanks
    G. Lakshmipathi

  • Display Distribution Lines, Invoice Number, and the PO Number

    In Toad, I'm trying to make a query that will display the invoice number and all distribution lines as well as if it's tied to a PO or not, and if so, what is the PO number - is this possible? This is what I've made so far and I don't think the outer joins are correct.
    from ap.ap_invoices_all inv
    ,po.po_vendors vend
    ,ap.ap_invoice_distributions_all idstr
    ,gl.gl_code_combinations distr
    ,po.po_distributions_all pdstr
    ,po.po_line_locations_all shipm
    ,po.po_lines_all polin
    ,po.po_headers_all pohdr
    where vend.vendor_id = inv.vendor_id
    and inv.invoice_id = idstr.invoice_id
    and idstr.dist_code_combination_id = distr.code_combination_id
    and idstr.po_distribution_id = pdstr.po_distribution_id(+)
    and pdstr.line_location_id = shipm.line_location_id (+)
    and shipm.po_line_id = polin.po_line_id (+)
    and pohdr.po_header_id (+) = polin.po_header_id

    Hi,
    If your PO is in SRM (and replicated into R/3), and the GR is created directly in R/3, then there is no reference of this R/3 GR in SRM. The only way to get it it to read the backend PO history.
    To do this, you can try to call the BBP_PD_PO_GETDETAIL is SRM, with I_READ_BE_DATA = 'X'.
    You will get your R/3 reference (R/3 material doc number) in export tables E_HEADER_REL and E_ITMLIM_REL, and actual item values in E_ACTVAL.
    Rgds
    Christophe
    PS: please reward points for helpful answers

  • Excise Invoice number and Internal Number

    Hello Friends
    I have some queries ,I will be thankful to you if you could guide me, in understanding themu2026
    1) When we see the document in J1IEX ,in excise invoice tab, we see two fields :Excise invoice number and Internal Number.
    For Internal number we define the range in object J_1INTNUM, but how do we define range for Excise invoice  number
    2) Where do we maintain the relation between GRPO (Excise Transaction type) with the Excise Invoice number
    3) When do we require updating of register ,is it done on daily bases, and  how can we see the entries of RG23A part 1.
    4) We have excise invoice number  range of posted ,in process and cancel documents which is  assigned to GRPO transaction type, while running J1I7 though we select last option   part 1 posted  and part 2 not  posted, still the system shows the cancelled documents, How can I avoid  the cancel documents
    Thanks
    Siddharth

    1) When we see the document in J1IEX ,in excise invoice tab, we see two fields :Excise invoice number and Internal Number.
    For Internal number we define the range in object J_1INTNUM, but how do we define range for Excise invoice number
    -->> Ex inv nbr will be entered based on the vendor ex invoice .. this is external nbr assignment
    2) Where do we maintain the relation between GRPO (Excise Transaction type) with the Excise Invoice number
    --->> there is no relation between grpo vs. ex inv nbr
    3) When do we require updating of register ,is it done on daily bases, and how can we see the entries of RG23A part 1.
    >> u can see in J1I7 or thru table J_1IPART1
    4) We have excise invoice number range of posted ,in process and cancel documents which is assigned to GRPO transaction type, while running J1I7 though we select last option part 1 posted and part 2 not posted, still the system shows the cancelled documents, How can I avoid the cancel documents
    >> wait for others answers..

  • In order confirmation i need invoice number and delivery number.

    Dear Experts,
    I need invoice number and delivery number in order confirmation.
    how can i get the delivery number an invoice number.
    Program name: RVADOR01
    Regards
    Ahmed

    Hi
    In the Order confirmation Only sales order details will be there
    You better write a PERFORM  statement in Script and in the subroutine fetch the Delivery number and Invoice number with the following links and display them in script
    LIPS-VGBEL = VBAK-VBELN
    LIPS-VGPOS = VBAP-POSNR
    VBRP-AUBEL = VBAK-VBELN
    VBRP-AUPOS = VBAP-POSNR
    You can also can use the VBFA table
    using Prev doc type = C (order) and Subsequent doc type = J to get the Delivery
    and Sunsequent type = M for getting the Invoice Number
    see the sample code for subroutine
    REPORT ZMPO1 .
    form get_freight tables in_par structure itcsy out_par structure itcsy.
    tables: ekko,konv,t685t.
    data: begin of itab occurs 0,
             ebeln like ekko-ebeln,
             knumv like ekko-knumv,
           end of itab.
    data: begin of itab1 occurs 0,
             knumv like konv-knumv,
             kposn like konv-kposn,
             kschl like konv-kschl,
             kbetr like konv-kbetr,
             waers like konv-waers,
             kwert like konv-kwert,
           end of itab1.
    data: begin of iout occurs 0,
             kschl like konv-kschl,
             vtext like t685t-vtext,
             kbetr like konv-kbetr,
             kwert like konv-kwert,
           end of iout.
    data v_po like ekko-ebeln.
    read table in_par with key 'EKKO-EBELN'.
    if sy-subrc = 0.
       v_po = in_par-value.
       select
         ebeln
         knumv
      from ekko
      into table itab
      where ebeln = v_po.
      if sy-subrc = 0.
        loop at itab.
          select
            knumv
            kposn
            kschl
            kbetr
            waers
            kwert
          into table itab1
          from konv
          where knumv = itab-knumv and
                kappl = 'M'.
        endloop.
        loop at itab1.
          if itab1-kposn <> 0.
            select single * from t685t
                              where kschl = itab1-kschl
                                and kappl = 'M'
                                and spras = 'EN'.
            iout-vtext = t685t-vtext.
            iout-kschl = itab1-kschl.
            iout-kbetr = itab1-kbetr.
            iout-kwert = itab1-kwert.
            append iout.
            clear iout.
          endif.
        endloop.
        sort itab1 by kposn.
        loop at iout.
          sort iout by kschl.
          if ( iout-kschl eq 'GSDC' OR
               iout-kschl eq 'GSFR' OR
               iout-kschl eq 'GSIR' ).
            at end of kschl.
              read table iout index sy-tabix.
              sum.
             write:/ iout-kschl,iout-vtext,iout-kwert.
          out_par-name = 'A1'.
          out_par-value = iout-vtext.
          append out_par.
          out_par-name = 'A2'.
          out_par-value = iout-kwert.
          append out_par.
              endat.
            endif.
          endloop.
        endif.
      endif.
    endform.
    IN THE FORM I AM WRITING THIS CODE.
    /:DEFINE &A1& = ' '
    /:DEFINE &A2& = ' '
    /:PERFORM GET_FREIGHT IN PROGRAM ZMFORM_PO1
    /:USING &EKKO-EBELN&
    /:CHANGING &A1&
    /:CHANGING &A2&
    /:ENDPERFORM
    &A1&
    &A2&
    This Code is to be written in the PO form under ADDRESS window.
    /:DEFINE &A1& = ' '
    /:DEFINE &A2& = ' '
    /:DEFINE &A3& = ' '
    /:DEFINE &A4& = ' '
    /:DEFINE &A5& = ' '
    /:DEFINE &A6& = ' '
    /:PERFORM GET_VENDOR IN PROGRAM ZMFORM_PO
    /:USING &EKKO-EBELN&
    /:CHANGING &A1&
    /:CHANGING &A2&
    /:CHANGING &A3&
    /:CHANGING &A4&
    /:CHANGING &A5&
    /:CHANGING &A6&
    /:ENDPERFORM
    &A1&
    &A2&
    &A3&
    &A4&
    &A5&
    &A6&
    Regards
    Anji

  • Invoice number and Check number for FI

    Hi Friends,
                    What does the above for FI mean? I need to pull the invoice number and the check numbers from AP and report . My question how do I recognize
    which field from 0FI_GL_4 stores this information? Any advice would be greatly appreciated,
    Assumption : Are the check numbers in FI nothing but the document numbers for a particular document type?
    Thank you,

    FI means Financial accounting.  0FI_GL_4 does not contain the check number as a standard field in the extractor. You would have to modify the extractor. the check number is in the table PAYR field CHECT linked to the clearing document  number VBLNR . The clearing doc is in 0FI_GL_4 so that is your connection. You probably would be futher ahead to create an extracotr for PAYR then connect to your data from 0FI_GL_4 in an MP or info set.  By the way 0FI_AP_4 is the extractor for accounts payable so you may want to use this instead. Depends if  like they are requsting accounts payable information. The invoice number will be in the reference field which is XBLNR.
    pls assign points to say thanks.

  • Invoice number and document number not printed in payment advice

    Hello Gurus,
           I am executing reprint check through transaction fch7, In that Invoice number and document number not printed in payment advice. I have created zscript for that and also assinged regup-belnr and regup-xblnr and used standard program RFFOUS_C.
    other fields from regup table are displayed but above two mentioned fields are not displayed.
          I even tried debugging standard RFFOUS_C prog, in that regup-belnr and regup-xblnr are coming but it is not printed on form.
    With regards,
    Vikram

    Hi,
    Debug you Zscript and check the invoice no and document no. Have assigned that script in FBZP..? check the which form is calling FCH7 in debugger mode..?
    Rgds
    Aeda.

  • Invoice Number and Performa invoice number

    Hi all
      I want to get the combination of invoice Number and Performa invoice number, I have got the VBFA Table, but it’s very slow, any alternative program or function please help me
    Thanks
    Kanishka

    Try AC_DOCUMENT_RECORD. It returns all kind of accounting documents.

  • Invoice Number and Document Number

    Are Invoice Number and Document Number in FI AR same?
    Dont they differ, I could find only one infoobject 0INV_DOC_NO relating to both.
    Is there any seperate infoobject which gives the document number in 0FIAR_C03.
    Please comment.
    Thanks.

    hi,
    are you looking for clearing doc number ?
    http://help.sap.com/saphelp_nw04s/helpdata/en/ee/cd143c5db89b00e10000000a114084/frameset.htm
    0CLR_DOC_NO - source field BSID-AUGBL
    hope this helps.

  • Make "invoice number" and "description" fields both mandatory on payables

    I want my 'invoice number" and "description" fields both manadatory on quick invoice to force users to fill in the fields.

    995170 wrote:
    I want my 'invoice number" and "description" fields both manadatory on quick invoice to force users to fill in the fields.Please see my reply to your other thread -- https://forums.oracle.com/forums/thread.jspa?threadID=2514322
    Thanks,
    Hussein

  • Printing invoice number and purchase order

    Hi All,
             I am newbie to SAP scripts.By using standard script ( f110_prenum_chk  ) modifying the script layout.and also need to print some extra fields.those are ,
                                --  Invoice number
                                --  Purchase order number
                                --  TDS
    from the above  i am able to display TDS by using the field &regud-sqste& .Is this right field to print the TDS ?
    and from which table i can fetch the details of invoice number ,and PO number ?i have the document number (reguh-vblnr).can i use this field to fetch the details of  invoice and PO numbr.please Help me out.
    Thanks and regards
    Naresh
    Edited by: naresh bammidi on Oct 12, 2011 2:17 PM

    Hi,
    You ERP system should be upgraded to Enhancement pack 3 to avail this datasource. Could you confirm the patch level of your ECC system. Or you can use 2lis_06_inv datasource to get the PO Number and accounting information.
    Thanks,
    RRR.
    Edited by: Rammi on Feb 18, 2010 10:11 AM
    Edited by: Rammi on Feb 18, 2010 10:12 AM
    Edited by: Rammi on Feb 18, 2010 10:12 AM

  • Link between invoice number and accounting document number

    Hi Frnds,
    When i receive a partial receipt (of an invoice) from a customer, i am getting the link between invoice number and accounting document number from a table (BSEG), but when i am receiving the final settlement amount from the customer, i m not getting the link between the inv. no. and accounting document number. Can anyone tell me how can i get the same?

    hi
    try these tcodes
    FBL5N
    FB02
    regards

  • How to find ar invoice number and order_number in gl

    hai all
    plase send ane one pfd are some other documents how to find the ar invoice number and order number in gl tables are in gl_interface

    11i (11.5.10.2+ virtual) Documentation Library
    http://download-uk.oracle.com/docs/cd/B25516_14/current/html/docset.html
    Release 12.0.4 Documentation Library
    http://download.oracle.com/docs/cd/B40089_09/current/html/docset.html

  • LOV query is invalid, a display and a return value are needed

    hello - i am having this issue and can't get around this when creating a popup LOV based on sql.
    below is LOV query. as you see the view has only two columns. I tried various ways by giving alias to columns in query but nothing works. What did I miss here?
    select description,inventory_item_id from xx_apex_inv_v
    1 error has occurred
    LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.

    Did you try it like this?
    select description d, inventory_item_id v from xx_apex_inv_v

  • XML document convert into String and Insert into Database

    Hello all,
         In the FIle to File Scenario  I want to send the data to the Reciever System in xml Document and convert into String and insert into Database.
      Please can you tell me exact way how to send it.
    Thanks & Regards,
    Raj

    HI,
    As per my understanding your scenario is File to file where you will get output fiel in XML format.
    Now that XMl payload need to be passed as single string in the database via XI.
    You cauld do this but you need to imply some manipulations such as
    With the help of standard API you need to concatenate the  XML tags and create the structre along with the data.
    For e.g. in your outpuf file the XML structre contain data as
    <field1>ABCD</field1>
    Then in mapping
    The source field will be mappeda s concat(<field1>) + value of  Source field "ABCD" + concat(</field1>) to the target field.
    This is the way that you could achive the requirments else there is no direct way avaialble for it.
    thanks
    Swarup

Maybe you are looking for