如下:
一张表 testa b c da1 b1 2012-12-13 20:30:30 null
a2 b2 2012-12-13 20:30:30 2012-12-13 20:30:30
a3 b3 2012-12-13 20:30:30 null
a4 b4 2012-12-13 20:30:30 2012-12-13 20:30:30
a5 b5 2012-12-13 20:30:30 null
a6 b6 2012-12-13 20:30:30 2012-12-13 20:30:30
最后的效果是
a b c da1 b1 2012-12-13 20:30:30 null
a3 b3 2012-12-13 20:30:30 null
a5 b5 2012-12-13 20:30:30 null
a4 b4 2012-12-13 20:30:30 2012-12-13 20:30:30
a2 b2 2012-12-13 20:30:30 2012-12-13 20:30:30
a6 b6 2012-12-13 20:30:30 2012-12-13 20:30:30where 是根据d 是否为null 来组合显示。 排序是按照 c的时间来desc 。 谢谢
一张表 testa b c da1 b1 2012-12-13 20:30:30 null
a2 b2 2012-12-13 20:30:30 2012-12-13 20:30:30
a3 b3 2012-12-13 20:30:30 null
a4 b4 2012-12-13 20:30:30 2012-12-13 20:30:30
a5 b5 2012-12-13 20:30:30 null
a6 b6 2012-12-13 20:30:30 2012-12-13 20:30:30
最后的效果是
a b c da1 b1 2012-12-13 20:30:30 null
a3 b3 2012-12-13 20:30:30 null
a5 b5 2012-12-13 20:30:30 null
a4 b4 2012-12-13 20:30:30 2012-12-13 20:30:30
a2 b2 2012-12-13 20:30:30 2012-12-13 20:30:30
a6 b6 2012-12-13 20:30:30 2012-12-13 20:30:30where 是根据d 是否为null 来组合显示。 排序是按照 c的时间来desc 。 谢谢
解决方案 »
- 一条简单语句错在哪
- 既要用LIKE 有要用等号 而且是或得关系
- mysql能解决双系统下乱码问题吗
- WinXP 下使用 MySQL 命令 : source filename, 如何记录 log ?
- 在mysql中用什么语句查询所有的数据库名字
- 如何查询字段不为空的记录?
- MySQL设置密码的问题
- 在局域网内的mysql server,我明明已经给root用户(其他用户也一样)增加了密码了的,
- mysql -u root -p root pdms <d:\pdms\backdebug\0724.ful 数据导不回
- 请问怎样在Windows和Linux下访问远程(inter网)MySQL服务?
- 数据表字段怎么求和?
- MYSQL中为什么调用这个存储过程老是报错啊
from 表
order by d, c desc
纯排序嘛,没有什么组合。
如果你一定要确定 null 的排序,可以用这个:
select *
from 表
order by isnull(d) desc, c desc
order by isnull(d) desc,c desc
order by case when d is null then 1 else 2 end,c desc