Convert decimal value to top 10

后端 未结 3 1956
执笔经年
执笔经年 2021-01-27 07:45

I recived some great help earlier today but it was more difficult when I should implement it in my query than I thought. My real query includes several left joins.

I wa

3条回答
  •  长情又很酷
    2021-01-27 08:06

    It is a bit tricky, maybe is it this what you are looking for?

    SELECT
      q2.*,
      CASE WHEN @row>1 AND T1G is not NULL THEN @row:=@row-1 ELSE 1 END T1GOutput
    FROM (
    
    SELECT
      q1.*,
      CASE WHEN @row>1 AND T3M is not NULL THEN @row:=@row-1 ELSE 1 END T3MOutput
    FROM (
    SELECT
      base.number as NR,
      rank.rpo as RPO,
      rank.rsp as RSP,
      rank.rsv as RSV,
      timer.t3m as T3M,
      timer.t1g AS T1G
    FROM
    
      round LEFT JOIN base 
      ON round.id = base.round_id 
    
      LEFT JOIN rank 
      ON round.id = rank.round_id and rank.number = base.number
    
      LEFT JOIN timer    
      ON round.id = timer.round_id and timer.number = base.number
    
    order by T3M DESC
      ) q1, (SELECT @row:=11) rows
    ) q2,  (SELECT @row:=11) rows
    ORDER BY
      T1G
    

    Please see fiddle here.

提交回复
热议问题