MySQL:按字段排序,在末尾放置空单元格 [英] MySQL: Order by field, placing empty cells at end

查看:83
本文介绍了MySQL:按字段排序,在末尾放置空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多产品的MySQL表.我想做的是按一个特定的列对表进行排序(大多数值以数字开头,例如:1st,2nd),等等.但是,由于某些记录没有此列的值,因此当我尝试排序时,表格会自动将空行置于FIRST.

I have a MySQL table which contains a number of products. What I want to do is sort the table by one particular column (most of the values begin with numbers for example: 1st, 2nd), etc. However, since some records do not have a value for this column, when I try to sort, the table automatically puts empty rows FIRST.

我正在寻找一种对ASCENDING行进行排序的方法,但是如果有意义的话,只能在已排序记录的末尾插入空白记录?

I am looking for a way to sort the row ASCENDING, but only insert blank records at the end of the sorted records, if that makes sense?

我们将非常感谢您的帮助!

Any help would be most gratefully received!

推荐答案

select * from table
order by if(field = '' or field is null,1,0),field

这篇关于MySQL:按字段排序,在末尾放置空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆