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
  • 25,246
  • 15
  • 42
  • 71
Kristina
  • 261
  • 2
  • 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
  • 502,043
  • 27
  • 286
  • 360
1
CASE WHEN SUM(status) = COUNT(status) THEN 1 ELSE 0 END AS product
Dale K
  • 25,246
  • 15
  • 42
  • 71
lili
  • 83
  • 9
  • 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