我想要做的是添加另一列,计算(cr - dr)。
由于在SELECT子句中不能重复使用别名,你如何计算total
?
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 ....
我想要做的是添加另一列,计算(cr - dr)。
由于在SELECT子句中不能重复使用别名,你如何计算total
?
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 ....
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;
SELECT
@dr:=SUM(b.bet_win * cy.fx_rate ),
@cr:=SUM(b.bet_loss * cy.fx_rate ),
@cr+@dr as total
SELECT
SUM(b.bet_win * cy.fx_rate) as dr,
SUM(b.bet_loss * cy.fx_rate) as cr,
SUM(b.bet_win * cy.fx_rate) + SUM(b.bet_loss * cy.fx_rate) as total
FROM ....
WHERE ....