让我们首先创建一个表-
mysql> create table DemoTable ( StudentId varchar(40) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('10'); mysql> insert into DemoTable values(20); mysql> insert into DemoTable values('~'); mysql> insert into DemoTable values(NULL); mysql> insert into DemoTable values('40'); mysql> insert into DemoTable values(NULL);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+ | StudentId | +-----------+ | 10 | | 20 | | ~ | | NULL | | 40 | | NULL | +-----------+ 6 rows in set (0.00 sec)
以下是对MySQL中特殊字符排序的查询-
mysql> select *from DemoTable order by case when StudentId not like '%[^a-zA-Z0-9]%' THEN 80 when StudentId is null then 98 else 85 end,StudentId;
这将产生以下输出-
+-----------+ | StudentId | +-----------+ | ~ | | 10 | | 20 | | 40 | | NULL | | NULL | +-----------+ 6 rows in set (0.03 sec)