質問

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.

役に立ちましたか?

解決

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

他のヒント

According to your last comment, the query should be following

SELECT Amount * (LA + MD)
FROM test    
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top