Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Posts
    5

    Question Unanswered: SUM PRODUCTS Possible in SQL?

    Hi,

    Let's say I have 2 tables, A an B and I Inner Join them on a common ID field. Each table has a Quantity Field. For all records in (A Join B) I want to multiply A.Quantity * B.Quantity and Sum All of the Results. This is similar to the SUMPRODUCT Function in Microsoft Excel. Is this possible in SQL?? If so, how??

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    dunno if the excel function is the same as this, but here's what you want in sql --
    Code:
    select sum(A.quantity * B.quantity) as SumAxB
      from A inner join B on A.ID = B.ID
    of course, that's the sum for the entire table

    if you want the sum for each ID, it's --
    Code:
    select A.id
         , sum(A.quantity * B.quantity) as SumAxB
      from A inner join B on A.ID = B.ID
    group
        by A.ID
    rudy
    http://rudy.ca/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •