MySQL ORDER BY 带下划线的字符串?
mysqlmysqli database更新于 2025/12/15 23:08:17
首先我们创建一个表 −
mysql> create table DemoTable ( Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('John_Smith');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('Chris Brown');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('John_Doe');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('David Miller');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('Carol Taylor');
Query OK, 1 row affected (0.13 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+--------------+ | Name | +--------------+ | John_Smith | | Chris Brown | | John_Doe | | David Miller | | Carol Taylor | +--------------+ 5 rows in set (0.00 sec)
以下是按带下划线的字符串排序的查询 −
mysql> select *from DemoTable order by (Name LIKE 'John_%') DESC,rand();
这将产生以下输出 −
+--------------+ | Name | +--------------+ | John_Doe | | John_Smith | | Carol Taylor | | David Miller | | Chris Brown | +--------------+ 5 rows in set (0.42 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

