How can I multiply numbers (data) in one column in MySQL?

How can I multiply all numbers in one column?

eg:

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

      

I know how to use the amount.

sum(Status)=4

      

I need something like a sum to multiply

mul(status)=0

      

do we have something like mul(status)

?

+1


source to share


2 answers


I don't know the function of multiplying the aggregate. However, in the case of a column containing only zeros and ones, the product will be the same only if each value is equal to one, otherwise it will be equal to zero:



SELECT
    CASE WHEN SUM(status) = COUNT(status) THEN 1 ELSE 0 END AS product
FROM yourTable

      

+1


source


CASE WHEN SUM(status) = COUNT(status) THEN 1 ELSE 0 END AS product

      



+2


source







All Articles