Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2015
    Posts
    22

    Unanswered: Multiplying values from different rows

    Hello all,

    I am now learning SQL and I have one question. I would like to retrieve the last row's data from the table above it.
    Meaning that I would like to group the data based on the number 10248, receiving the product of the three numbers of the table rows (11*42*72).
    Probably for someone else this should be super easy but I don't know the methodology to do something like that.
    Every help is much appreciated. Thanks!

    A B C

    1 10248 11
    2 10248 42
    3 10248 72


    10248 3 33264

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    629
    Provided Answers: 33
    Code:
    sub multiplyAll()
    dim dAmt as double
    dim sSql as string
    dim vVal 
    
    sSql = "select * from table"
    Set rst = currentdb.OpenRecordset(sSql)
    With rst
      While Not .EOF
         vVal = nz(.Fields("field").Value )
         dAmt = dAmt * vVal
         
         .MoveNext
      Wend
    End With
    
    msgbox dAMt
    end sub

Posting Permissions

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