create table #tmp(cust_code varchar(10),cdate datetime,amount money)
insert into #tmp values('BW','1/1/07',1000) insert into #tmp values('BW','1/2/07',500) insert into #tmp values('BW','1/3/07',4000) insert into #tmp values('MS','1/1/07',23000) insert into #tmp values('MS','1/2/07',10)
select a.cust_code,a.cdate,a.amount from (select t.cust_code,t.cdate,t.amount from #tmp t where cdate in (select min(cdate) from #tmp where cust_code=t.cust_code) group by t.cust_code,t.cdate,t.amount ) a group by a.cust_code,a.cdate,a.amount
go
drop table #tmp
|