Assume that a table has two columns named "x" and "y" filled with numbers; for example, x contains the values (1, 2, 3), and y contains (5, 8, 20).
How can I calculate the sum of the products of the columns, i.e. (1 × 5) + (2 × 8) + (3 × 20) = 81?
As Siyual notes in the comments, this should do the trick:
SELECT SUM(x * y) FROM Table
Here's a live demo on SQLize, just to confirm that this does work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With