0

我正在编写 MySQL 查询以对此类数据进行排序

Traffic
100/40
12/1
50/20
25/5

从左侧数字中除以右侧数字得到的值。

我也有多列进行排序

前任 - SELECT * FROM fltable ORDER BY Traffic DESC,Speed ASC,Cost ASC

我需要对这些数据进行升序降序排序,任何人都可以帮我解决这个问题。

谢谢

4

2 回答 2

2
SELECT * FROM fractions;
+-----------+
| fractions |
+-----------+
| 100/40    |
| 12/1      |
| 25/5      |
| 50/20     |
+-----------+

SELECT fractions
     , SUBSTRING_INDEX(fractions,'/',1)/SUBSTRING_INDEX(fractions,'/',-1)x 
  FROM fractions 
 ORDER 
    BY x DESC;
+-----------+------+
| fractions | x    |
+-----------+------+
| 12/1      |   12 |
| 25/5      |    5 |
| 100/40    |  2.5 |
| 50/20     |  2.5 |
+-----------+------+
于 2013-09-04T12:14:55.787 回答
1

尝试类似以下查询:

SELECT *, CONVERT(SUBSTR(var, 1, POSITION('/' IN var) - 1), UNSIGNED INTEGER) as num 
FROM table 
ORDER BY num DESC

/使用SUBSTRCONVERT到之前获取数字int

结果与num

100
50
25
12
于 2013-09-04T11:47:38.080 回答