0

我得到的单元格可能包含以下数据(错误数)

1
2
3
PASS
NoFileFound
NoLog
99
10
2

我想按升序和降序排序,其中我将 PASS 视为 0 值,任何其他基于文本的值应视为 1 错误值。截至目前,这些单元格作为“文本”存储在 mysql 数据库中。如何为 MYSQL 做到这一点?我需要做哪些改变?

4

1 回答 1

0

试试这个:

SELECT Number FROM (
   SELECT IF(valueField='PASS',0,1) as Number  FROM TableMix 
   WHERE concat('',valueField * 1) <> valueField ) A
UNION ALL
SELECT Number FROM (
  SELECT CAST(valueField as UNSIGNED) as Number  FROM TableMix 
  WHERE concat('',valueField * 1) = valueField ) B
ORDER BY Number

请参阅我的SqlFiddle 演示

而这个具有原始值的包括:

SELECT Number, valueField FROM (
   SELECT IF(valueField='PASS',0,1) as Number, valueField  FROM TableMix 
   WHERE concat('',valueField * 1) <> valueField ) A
UNION ALL
SELECT Number, valueField FROM (
  SELECT CAST(valueField as UNSIGNED) as Number, valueField  FROM TableMix 
  WHERE concat('',valueField * 1) = valueField ) B
ORDER BY Number

请参阅此演示

于 2013-11-09T04:25:07.447 回答