执行下面的语句
create table abc
(merch varchar(4),
date smalldatetime,
value int)
insert abc values ('a','2007/1/2',2)
insert abc values ('a','2008/5/3',3)
insert abc values ('a','2006/6/6',4)
insert abc values ('b','2004/6/8',5)
insert abc values ('b','2002/6/7',6)
insert abc values ('b','2008/4/5',7)复制代码
我想查出这样的结果:
merch
date
value
b
2008-04-05 00:00:00
7
a
2008-05-03 00:00:00
3复制代码
我现在用这样的语句查询:
select a.* from abc a,(select merch,max(date)'date' from abc group by merch) b
where a.merch=b.merch and a.date=b.date复制代码
但觉得有点麻烦,请问还有没有更简练的语句?
|