一般初学者的误区:
select * from student order by createtime, updatetime DESC;
所有指定的字段都以最后一个字段排序。
实际上:
mysql中 默认情况无排序,按照输入的先后排列。(也就是ID升序)
select * from student order by createtime, updatetime; --createtime升序,updatetime升序
select * from student order by createtime, updatetime DESC; -- createtime升序,updatetime降序
select * from student order by createtime DESC, updatetime ; -- createtime降序,updatetime升序
select * from student order by createtime DESC, updatetime DESC; -- createtime降序,updatetime降序
其实数据库是这么理解的
order by createtime [AES], updatetime [AES]; --createtime升序,updatetime升序
order by createtime [AES], updatetime DESC; -- createtime升序,updatetime降序
order by createtime DESC, updatetime [AES]; -- createtime降序,updatetime升序
order by createtime DESC, updatetime DESC; -- createtime降序,updatetime降序
中括号中就是我们省略的关键字。
详细介绍:http://www.w3school.com.cn/sql/sql_orderby.asp点击打开链接