我想要做的是添加另一个计算的列(cr – dr)
看到你不能在SELECT子句中重用别名,你会怎么去计算总计
SELECT SUM(b.bet_win * cy.fx_rate )as dr,SUM(b.bet_loss * cy.fx_rate ) as cr,cr+dr as total
FROM ....
WHERE ....
最佳答案
在SQL Server或Oracle中,我使用CTE,但由于您使用的是MySQL,因此您将使用子查询:
SELECT dr,cr,cr + dr as total
FROM (
SELECT
SUM(b.bet_win * cy.fx_rate ) as dr,SUM(b.bet_loss * cy.fx_rate ) as cr
FROM ....
WHERE ....) t;