SELECT
SUM(coins.available_supply * hist_all.price) AS market_cap_usd_all
FROM coins
LEFT JOIN hist_all ON coins.id = hist_all.coins_id
WHERE hist_all.price != 0
AND (hist_all.second_coin = 'USD' or hist_all.second_coin = 'USDT');
I try get sum market_cap_usd_all
, but in my table are rows with USD
and USDT
:
My query should like this:
if exists row second_coin = USD
, DON'T GET this same row with 'USDT', but if don't exists row with second_coin = USD
check if it exists row with second_coin = USDT
and get him. So the table should like this:
I don't know how write query with WHERE IF
I tried this:
... WHERE IF (hist_all.second_coin = 'USD', hist_all.second_coin = 'USD', hist_all.second_coin = 'USDT')
but it still sums all rows, both from USD and USDT.
market_cap_usd_all
fromUSD
andUSDT
, BUT IF EXIST USD, CAN NOT DOWNLOAD VALUE WITH USDT. For example I have 2 same records:first_coin = BTC
with USD and USDT, in this example I need get only value frommarket_cap_usd_all
wheresecond_coin = USD
.