How to Multiply all values within a column with SQL like SUM()

前端 未结 5 1868
忘掉有多难
忘掉有多难 2020-12-30 02:34

Lets say I have table with 1 column like this:

Col A
1
2
3
4

If I SUM it, then I will get this:

Col A
10
         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 03:32

    In MySQL you could use

    select max(sum)
    from 
    (
      select @sum := @sum * colA as sum 
      from your_table
      cross join (select @sum := 1) s
    ) tmp
    

    SQLFiddle demo

提交回复
热议问题