Question

I am trying to count the number of true values from a row, and so far it's looking good. After I get the value I would like to multiply that with the value from column 'Amount' in the same row.

Table test look like this, type of LA and MD are tinyint (checkbox)

ID   |  Amount |   LA   |   MD
------------------------------------
1    |    7    |   1    |   0
2    |    2    |   1    |   1

So far I can count true values from table test using:

SELECT count(*)
FROM test
WHERE LA = true

But ones I start implementing the multiplication it gets messy, not yet that steady on the syntax. Any tips would be greatly appreciated.

Was it helpful?

Solution

To take the correct result if you have LA=False and MD=True, try

SELECT Amount * (LA + MD)
FROM test
WHERE LA = true
    OR MD = true

OTHER TIPS

According to your last comment, the query should be following

SELECT Amount * (LA + MD)
FROM test    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top