Convert decimal value to top 10

随声附和 提交于 2019-12-02 07:55:05

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!