有表A
{
id int, --主键
datetimes datetime ,--时间
Autherinfoname varchar --姓名
...
}
我是想 根据Autherinfoname 和datetimes 进行排序
Autherinfoname 这有空值,Autherinfoname 空值跟Autherinfoname 不为空的数据进行分开,空值的数据放在不为空值的下边
然后根据时间进行排序
{
id int, --主键
datetimes datetime ,--时间
Autherinfoname varchar --姓名
...
}
我是想 根据Autherinfoname 和datetimes 进行排序
Autherinfoname 这有空值,Autherinfoname 空值跟Autherinfoname 不为空的数据进行分开,空值的数据放在不为空值的下边
然后根据时间进行排序
order by (case when Autherinfoname is null then 1 else 0 end),datetimes
order by (case when Autherinfoname is null then 1 else 0 end),datetimes
select * from 表A
order by (case when Autherinfoname is null or Autherinfoname='' then 1 else 0 end),datetimes
23 sdafd 2011-11-23 10:55:41.653
43 ewrtfst 2011-11-23 10:56:51.967
34 a 2011-11-23 11:07:13.217
34 b 2011-11-23 11:07:16.997
34 c 2011-11-23 11:07:20.233
34 ab 2011-11-23 11:07:29.687
34 ac 2011-11-23 11:07:34.030
34 ad 2011-11-23 11:07:37.170
33 00aa 2011-11-23 11:08:37.577
33 01aa 2011-11-23 11:08:41.763
33 02aa 2011-11-23 11:09:21.450
33 03aa 2011-11-23 11:09:35.530
34 2011-11-23 10:53:10.937
34 2011-11-23 10:53:14.293
34 2011-11-23 10:53:15.343
34 2011-11-23 10:53:16.733
34 2011-11-23 10:53:17.653
34 2011-11-23 10:53:18.873
34 2011-11-23 10:53:20.060
34 2011-11-23 10:53:20.793
43 2011-11-23 10:56:45.903
34 2011-11-23 11:07:08.043
33 2011-11-23 11:08:46.437
33 2011-11-23 11:09:27.590
以两列排序,但第一列由一个判断获得两个值,0,1,因为未指定desc,则0排在前.
第二个排序列以后面的 datetimes排序.