Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query the sum of a product

I want to write a query that returns the sum of two multiplied cells, where the name is equal to a person's name. Let's say I say I have:

Name score days
Suzie 5.0 3
Jonny 5.0 1
Suzie 4.0 1
Suzie 5.0 7
Jonny 4.0 1

basically, I want to know Suzie's average score. Some rows represent multiple days though. The arithmetic would be

(5.0 * 3)

  • (4.0 * 1)
  • (5.0 * 7)

I want to write a query:

=(index(query({a1:c3}, "Select Sum(Col2 * Col3) where Col1 = '" & D22 & "'"),2))

However, it doesn't like the part that says "Sum(Col2 * Col3)"

Is it possible to do the sum of two columns multiplied?

Thank you in advance!

like image 999
Neill Avatar asked Sep 05 '25 01:09

Neill


1 Answers

Please see this sample file.

Data

Col1    Col2    Col3
a         10     20
a         30     40
b         10     30

Result

a   1400
b   300

Formula

=QUERY({A2:A,ARRAYFORMULA(B2:B*C2:C)}, "select Col1, sum(Col2) where Col1 <> '' group by Col1")

like image 132
Max Makhrov Avatar answered Sep 07 '25 18:09

Max Makhrov