i have a table like this:
PO V1 V2 V3
1 2007-01-01 Aa a
2 2007-02-01 Bb b
2 2007-03-01 Cc c
1 2007-01-01 Dd d
1 2007-05-01 Ee e
i want get the Value of column V2,V3 , according minimal cloumn V1 ,in each group column PO.
how can i write the SQL statement ?
tahnks.Here it is,
Code Snippet
Create Table #data (
[PO] int ,
[V1] datetime ,
[V2] Varchar(100) ,
[V3] Varchar(100)
);
Insert Into #data Values('1','2007-01-01','Aa','a');
Insert Into #data Values('2','2007-02-01','Bb','b');
Insert Into #data Values('2','2007-03-01','Cc','c');
Insert Into #data Values('1','2007-01-01','Dd','d');
Insert Into #data Values('1','2007-05-01','Ee','e');
Select * from #data main
join (select po,min(v1) v1 from #data group by po) mindata
on main.po=mindata.po and main.v1=mindata.v1
No comments:
Post a Comment