{
id int, --主键
datetimes datetime ,--时间
Autherinfoname varchar --姓名
...
}
我是想 根据Autherinfoname 和datetimes 进行排序
Autherinfoname 这有空值,Autherinfoname 空值跟Autherinfoname 不为空的数据进行分开,空值的数据放在不为空值的下边
然后根据时间进行排序
17 个解决方案
#1
select * from 表A
order by (case when Autherinfoname is null then 1 else 0 end),datetimes
#2
被秒了
#3
#4
order by (case when Autherinfoname is null then 1 else 0 end),datetimes
#5
select * from 表a
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
#6
我补充下:Autherinfoname 的值可以为‘ ’,就是个空字符串
#7
select * from 表A
order by (case when Autherinfoname is null or Autherinfoname='' then 1 else 0 end),datetimes
#8
这不行,Autherinfoname 为空的数据和不为空的数据没有分开
#9
直接用测试数据和所需要的结果来说话。
#10
没有按时间排序
#11
撒旦法 12 bbb 2011-11-15 10:19:25.013
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
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
#12
为空的数据和不为空的数据分开了,但不为空的数据没有按时间进行排序
#13
学习,, 求原理,求解释!!
#14
啥?! 你再看看,我怎么没看出来?
#15
你再仔细看看,到底有没有排序,反正我看是排了.
#16
以两列排序,但第一列由一个判断获得两个值,0,1,因为未指定desc,则0排在前.
第二个排序列以后面的 datetimes排序.
#17
恩,我看错了@!谢谢各位大神了
#1
select * from 表A
order by (case when Autherinfoname is null then 1 else 0 end),datetimes
#2
被秒了
#3
#4
order by (case when Autherinfoname is null then 1 else 0 end),datetimes
#5
select * from 表a
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
#6
我补充下:Autherinfoname 的值可以为‘ ’,就是个空字符串
#7
select * from 表A
order by (case when Autherinfoname is null or Autherinfoname='' then 1 else 0 end),datetimes
#8
这不行,Autherinfoname 为空的数据和不为空的数据没有分开
#9
直接用测试数据和所需要的结果来说话。
#10
没有按时间排序
#11
撒旦法 12 bbb 2011-11-15 10:19:25.013
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
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
#12
为空的数据和不为空的数据分开了,但不为空的数据没有按时间进行排序
#13
学习,, 求原理,求解释!!
#14
啥?! 你再看看,我怎么没看出来?
#15
你再仔细看看,到底有没有排序,反正我看是排了.
#16
以两列排序,但第一列由一个判断获得两个值,0,1,因为未指定desc,则0排在前.
第二个排序列以后面的 datetimes排序.
#17
恩,我看错了@!谢谢各位大神了