1

How can I multiply all numbers in one column?

for example:

Status(finished or not finished)
            1
            1
            1
            1
            0

I know how to use sum.

sum(Status)=4

I need some thing like sum for multiply

mul(status)=0

do we have something like mul(status)?

Dale K
  • 21,987
  • 13
  • 41
  • 69
Kristina
  • 251
  • 1
  • 13

2 Answers2

1

I don't know of a multiply aggregate function. However, in the case of a column containing only zeroes and ones the product will be one only if every value be one, otherwise it will be zero:

SELECT
    CASE WHEN SUM(status) = COUNT(status) THEN 1 ELSE 0 END AS product
FROM yourTable
Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318
1
CASE WHEN SUM(status) = COUNT(status) THEN 1 ELSE 0 END AS product
Dale K
  • 21,987
  • 13
  • 41
  • 69
lili
  • 83
  • 8
  • Answers in SO should contain some text explaining why it is the answer in addition to corrected code. – Dale K Jul 12 '19 at 02:08