我有这张桌子:
create table #tmp
(
column1 varchar(3),
column2 varchar(5),
column3 datetime,
column4 int
)
insert into #tmp values ('AAA', 'SKA', '2013-02-01 00:00:00', 10)
insert into #tmp values ('AAA', 'SKA', '2013-01-31 00:00:00', 15)
insert into #tmp values ('AAA', 'SKB', '2013-01-31 00:00:00', 20)
insert into #tmp values ('AAA', 'SKB', '2013-01-15 00:00:00', 5)
insert into #tmp values ('AAA', 'SKC', '2013-02-01 00:00:00', 25)
我想选择具有不同column2 的行,按column3 排序。这是期望的结果:
Col1 Col2 Col3 Col4
AAA SKB 2013-01-15 00:00:00.000 5
AAA SKA 2013-01-31 00:00:00.000 15
AAA SKC 2013-02-01 00:00:00.000 25
我怎样才能做到这一点?
我正在使用 MS SQL 2005 和 2008