reusing alias in SELECT

后端 未结 3 1857
长情又很酷
长情又很酷 2021-01-05 07:24

What I am trying to do is add another column that calculates (cr - dr)

Seeing as you cannot re-use an alias inside a SELECT clause, how would you go about calculatin

3条回答
  •  甜味超标
    2021-01-05 07:59

    EDIT: DOES NOT WORK. See comments. Isn't using a user variable faster in this case?

    SELECT
      @dr:=SUM(b.bet_win * cy.fx_rate ),
      @cr:=SUM(b.bet_loss * cy.fx_rate ), 
      @cr+@dr as total
    

提交回复
热议问题