K
K
Kirill25012021-07-27 21:51:06
SQL
Kirill2501, 2021-07-27 21:51:06

How to do multiplication in Select?

Who knows, help me fix the error, I don’t know how to do it, and whether it’s possible at all .. The bottom line is that I want to add the condition “if” currency = 0 (the site is not fresh, the essence is, if 0, then it is displayed in dollars, if 1 - rubles), then the payout amount will be multiplied by 73 (approximate dollar exchange rate), did so, everything is displayed, but the condition is not met

$db->Query("SELECT * FROM project WHERE project_status = 1 OR project_status = 2 AND (IF(valuta = 0,payments * 73,payments))  ORDER BY vip DESC, payments DESC");

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Akina, 2021-07-27
@Kirill2501

SELECT CASE valuta WHEN 1 THEN price
                   WHEN 0 THEN price * 73
                   ELSE NULL 
                   END AS price_in_rub, 
       ...
FROM ...
WHERE ...

E
egor_nullptr, 2021-07-27
@egor_nullptr

select *, price * (73 - (72 * valuta)) as price_in_rub
from ...
where ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question