[英]How to sort a mysql table with null column values
I have a table with following schema. 我有一个具有以下架构的表。 I need to sort table by points , and if rows wiith img_link present (not null ) come first also.
我需要按点对表进行排序,如果存在img_link (不为null )的行也排在第一位。 Simply need to do is - sort by int column , then by varchar column .
只需要做的就是按int列排序,然后按varchar列排序。
+-----+--------+-----------+-----------+
| id | name | img_link | points |
+-----+--------+-----------+-----------+
| 11 | smpl | path.jpg | 10 |
+-----+--------+-----------+-----------+
| 12 | main | null | 20 |
+-----+--------+-----------+-----------+
| 13 | abcd | null | 10 |
+-----+--------+-----------+-----------+
| 14 | xyls | img_.png | 10 |
+-----+--------+-----------+-----------+
need a result like 需要一个类似的结果
+-----+
| id |
+-----+
| 12 |
+-----+
| 11 |
+-----+
| 14 |
+-----+
| 13 |
+-----+
Thanks in advance.. 提前致谢..
尝试这个
SELECT * FROM table_name ORDER BY points DESC ,ISNULL(img_link), img_link
尝试这个:
select * from tabalename where img_link is not null order by point desc union select * from tabalename where img_link is null order by point desc
SELECT * FROM my_table ORDER BY points DESC, img_link IS NULL, img_link DESC;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.