Mysql
 sql >> Database >  >> RDS >> Mysql

riutilizzare l'alias in SELECT

In SQL Server o Oracle, userei un CTE, ma poiché stai usando MySQL, useresti una sottoquery:

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;