Question:

SQL Multiplication of all values in a column?

by  |  earlier

0 LIKES UnLike

I need to be able to multiply all the values in one particular column, without knowing the number of records. I have searched and can't find a function that does that.

 Tags:

   Report

4 ANSWERS


  1. if you want to multiply each individual record just do

    let's say you have a column called "sales" and you want to multiply it by 10 (and table name is mytable)

    SELECT SALES*10 AS NEWSALES FROM MYTABLE

    if you want just the total do

    SELECT SUM(SALES*10) AS NEWSALES FROM MYTABLE


  2. You have to write your own function by looping through all the values until you get a non-numeric (blank) value.

  3. select exp(sum(log(your_column))) from your_table

  4. While you could multiply values of different columns together (or other computations, for that matter) for each row, there is no way to multiply all the values for a given column together via SQL. You'll need to execute a script and fetch the values from a cursor for that.  

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.