Home > Backend Development > PHP Tutorial > mysql 字段排序,该如何处理

mysql 字段排序,该如何处理

WBOY
Release: 2016-06-13 10:27:26
Original
937 people have browsed it

mysql 字段排序
在一个sql语句中如果如果需要排序的字段是空的,怎样处理啊,如果想把它排在后面怎么弄啊?

------解决方案--------------------
如果要排序的字段是空,默认会把为空的排在前面。加一个DESC关键词就可倒序排列,也就是空的在最后面
------解决方案--------------------
建议你贴出:
create table.......
insert into table.......

以及期望结果。
------解决方案--------------------
ORDER by isnull(`要按值排序的字段`)
就可以把为空的排在后面,你是这个意思吧?
------解决方案--------------------
(... WHERE 字段名字 IS NOT NULL GROUP BY 字段名字 )

UNION ( ... WHERE 字段名字 IS NULL )

……
------解决方案--------------------
... order by 排序字段='' or 排序字段 id null, 排序字段
------解决方案--------------------
为什么字段为空啊,建表时就应该尽量为非空。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template