簡體   English   中英

我如何修改這個 SQL 查詢的結果?

[英]How do i modify the result of this SQL query?

這是當前查詢

select usr.COUNTRY,
round(ifnull(sum(CASE when de.comment like '%BT%' THEN de.PROFIT END),0),2) AS OCPAY,
round(ifnull(sum(CASE when de.comment like '%XP%' THEN de.PROFIT END),0),2) AS XPAY,
round(ifnull(sum(CASE when de.comment like '%PA%' THEN de.PROFIT END),0),2) AS DRAGONPAY,
round(ifnull(sum(CASE when de.comment NOT like '%UT%' THEN de.PROFIT END),0),2) AS TOTAL_DEPOSIT,
#Markup
Case when
usr.country = 'Philippines' then round(ifnull(sum(de.PROFIT*0.02),0),2) Else
round(ifnull(sum(de.PROFIT*0.0055),0),2)
END AS 'Deposit_Bonus'
FROM svgdbgom_svgmt5db.mt5_users usr
inner join svgdbgom_svgmt5db.mt5_deals de using (login)
WHERE symbol = ''
and profit > 0
and usr.group not like '%test%'
and country <> 'China'
and de.time between '2022-04-01 00:00:00' and '2022-04-12 23:59:59'
and de.comment not like '%UT%'
and de.comment not like '%NT%'
and de.comment not like '%SK%'
and usr.name not like '%FXCE%'
and de.comment like '%2204%'
group by country),



Withdrawal as
(select usr.COUNTRY,
round(ifnull(sum(CASE when de.comment like '%BT%' THEN de.PROFIT END),0),2) AS OCPAY,
round(ifnull(sum(CASE when de.comment like '%XP%' THEN de.PROFIT END),0),2) AS XPAY,
round(ifnull(sum(CASE when de.comment like '%PA%' THEN de.PROFIT END),0),2) AS DRAGONPAY,
round(ifnull(sum(CASE when de.comment NOT like '%UT%' THEN de.PROFIT END),0),2) AS TOTAL_WITHDRAWAL,
# add
Case when
usr.country = 'Philippines' then round(ifnull(sum(de.PROFIT*0.02),0),2) Else
round(ifnull(sum(de.PROFIT*0.012),0),2)
END AS 'Withdrawal_Bonus'
FROM svgdbgom_svgmt5db.mt5_users usr
inner join svgdbgom_svgmt5db.mt5_deals de using (login)
WHERE symbol = ''
and country <> 'China'
and de.time between '2022-04-01 00:00:00' and '2022-04-12 23:59:59'
and usr.group not like '%test%'
and de.comment not like '%NT%'
and de.comment not like '%SK%'
and de.comment like '%Withdrawal%'
group by country
)
select *,case when
country = 'Vietnam' then '31093'
else '31092'
End as 'IB ACC', Deposit_Bonus-withdrawal_Bonus as TOTAL_BONUS from
deposit left join withdrawal
using (country)
order by country desc;

這是當前結果當前結果

總獎金假設等於存款獎金 + 提款獎金。 越南的總獎金是正確的,但菲律賓的總獎金是“空”而不是 42.00。 我該如何解決? 謝謝,我是 SQL 的新手

您的查詢需要 NULL 支票。

像這樣改變底部

select *,
case when
country = 'Vietnam' then '31093'
else '31092'
End as 'IB ACC', 
IFNULL(Deposit_Bonus,0.00)-IFNULL(withdrawal_Bonus,0.00) as TOTAL_BONUS from
deposit left join withdrawal
using (country)
order by country desc;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM