目前遇到的问题是这样的
比如说现有
列1
2012-12-31 21:55:00.000
2012-12-31 18:10:00.000
2012-12-31 22:10:00.000
2012-12-31 23:45:00.000
2012-12-31 12:25:00.000
2012-12-31 20:45:00.000
2012-12-31 21:25:00.000
2012-12-30 19:55:00.000
2013-01-01 20:25:00.000
2013-01-01 15:45:00.000
2013-01-01 19:00:00.000
2013-01-01 14:55:00.000
2013-01-01 06:35:00.000
2012-12-31 21:05:00.000
2012-12-31 19:05:00.000
2012-12-31 23:30:00.000
2012-12-31 21:05:00.000
列2
2013-01-01 20:25:00.000
2013-01-01 15:45:00.000
2013-01-01 19:00:00.000
2013-01-01 14:55:00.000
2013-01-01 06:35:00.000
2013-01-01 07:35:00.000
2013-01-01 07:45:00.000
2013-01-01 09:30:00.000
2012-12-31 21:05:00.000
2012-12-31 19:05:00.000
2012-12-31 23:30:00.000
2012-12-31 21:05:00.000
2013-01-01 07:10:00.000
2013-01-01 11:30:00.000
2013-01-01 07:40:00.000
2013-01-01 08:05:00.000
2013-01-01 08:25:00.000
2013-01-01 07:40:00.000
想得到的结果是列2的值中,比列1当前行值小的所有行的个数
比如这样
2012-12-31 21:55:00.000 3
之前用的是游标,但处理起来太耗时间,想用结果集的方法来做,大家有什么好方法吗?
2 个解决方案
select 列1,(select count(*) from table1 where 列2<a.列1) from table1 as a order by 列1