如何从MySql数据库中获取标题(表中的一行),以便标题按特定顺序排列

时间:2015-09-04 13:15:02

标签: mysql

我有以下查询

SELECT id,title,image,address,serviceType FROM `ta` ORDER BY title LIMIT 0,20 

它根据标题的排序给出了结果。

默认排序首先使用特殊字符开头'标题',然后是以数字开头的标题,然后是以字母开头的标题。

但我想要的是,首先以数字开头的标题,然后是以字母开头的标题,然后是以特殊字符开头的标题。

请帮忙。

2 个答案:

答案 0 :(得分:0)

您可以将case语句放在order by子句中。像这样的事情: -

<mount path="/_system/config" overwrite="true">
   <instanceId>gov</instanceId>
   <targetPath>/_system/config</targetPath>
</mount>

<mount path="/_system/governance" overwrite="true">
   <instanceId>gov</instanceId>
   <targetPath>/_system/governance</targetPath>
</mount>

希望这有帮助。

答案 1 :(得分:0)

如何提问:

你好,我有一张这样的表:

CREATE TABLE strings
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
,string VARCHAR(12) UNIQUE NOT NULL
);

INSERT INTO strings (string) VALUES 
('apple'),
('banana'),
('cherry'),
('*durian'),
('1eggplant'),
('10fig'),
('grapefruit');


SELECT * FROM strings;
+----+------------+
| id | string     |
+----+------------+
|  4 | *durian    |
|  6 | 10fig      |
|  5 | 1eggplant  |
|  1 | apple      |
|  2 | banana     |
|  3 | cherry     |
|  7 | grapefruit |
+----+------------+

我想要一个像这样的结果集......

[在此输出您想要的输出]

...行由x,y z排列。

我试过了......

[让你最好的努力]

......但这不对,因为它在以下方面是错误的......