有这样的一个表:
Time Sign SN
2013-01-01 AAA 1
2013-01-04 CCC 2
2013-01-06 BBB 3
2013-01-05 BBB 1
2013-01-02 AAA 2
2013-01-05 BBB 2
2013-01-06 BBB 4
2013-01-03 AAA 3
2013-01-04 AAA 4
2013-01-03 CCC 1
排序后要求是这样的:
Sign Time SN
AAA 2013-01-01 1
AAA 2013-01-02 2
AAA 2013-01-03 3
AAA 2013-01-04 4
CCC 2013-01-03 1
CCC 2013-01-04 2
BBB 2013-01-05 1
BBB 2013-01-05 2
BBB 2013-01-06 3
BBB 2013-01-06 4
------解决方案--------------------
是这样吗:
;with t(Time, Sign, SN)
as
(
select '2013-01-01', 'AAA', 1
union all select '2013-01-04', 'CCC', 2
union all select '2013-01-06', 'BBB', 3
union all select '2013-01-05', 'BBB', 1
union all select '2013-01-02', 'AAA', 2