Convert decimal value to top 10

后端 未结 3 1955
执笔经年
执笔经年 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.

    0 讨论(0)
  • 2021-01-27 08:19

    Assuming that you are trying to rank these values, One possible way of doing this is first determine the min and max values of T3M and T1G, then using something like this:

    SELECT ...,
           ((T3M-@T3M_Min)/(@T3M_Max-@T3M_Min))*9+1 as T3MOutput,
           ((T1G-@T1G_Min)/(@T1G_Max-@T1G_Min))*9+1 as T1GOutput
    

    There may have to be some conversion to an integer value

    0 讨论(0)
  • 2021-01-27 08:20

    First

    SELECT MIN(timer.t3m) AS MinT3M, MAX(timer.t3m) AS MaxT3M,
      MIN(timer.t1g) AS MinT1G, MAX(timer.t1g) AS MaxT1G
      FROM round INNER JOIN timer ON round.id = timer.round_id
      WHERE round.round_date = '2013-03-22' 
        AND round.gameform = 'V65'
        AND round.gameform_info = 'V65-1'
        AND round.gameform not like "OSPEC";
    

    Then you can use the calculation which Richard proposed while I was typing this.

    See the SQL Fiddle here which uses your data.

    0 讨论(0)
提交回复
热议问题