Вопрос

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