my data looks like the following
111 0 01/01/2007
111 0 02/01/2007
222 0 04/01/2007
222 0 05/01/2007
555 1 06/01/2007
666 0 06/01/2007
how can i retrieve the following?
111 0 01/01/2007
222 0 04/01/2007
555 1 06/01/2007
666 0 06/01/2007
my goal is to retrive distinct cols 1 and 2, and then the earliest date in
col 3 for distinct records in cols 1 and 2?
any suggestions? I tried different ways of using min a, but was
unsuccessful. I can get max to work which returns the latest date, but when
i switch to min, I dont get any records.
Thanks in advance.
> my data looks like the following
> 111 0 01/01/2007
> 111 0 02/01/2007
> 222 0 04/01/2007
> 222 0 05/01/2007
> 555 1 06/01/2007
> 666 0 06/01/2007
> how can i retrieve the following?
> 111 0 01/01/2007
> 222 0 04/01/2007
> 555 1 06/01/2007
> 666 0 06/01/2007
> my goal is to retrive distinct cols 1 and 2, and then the earliest date in
> col 3 for distinct records in cols 1 and 2?
> any suggestions? I tried different ways of using min a, but was
> unsuccessful. I can get max to work which returns the latest date, but
> when i switch to min, I dont get any records.
> Thanks in advance.
This should solve it.
create table #test (col1 int, col2 int, col3 datetime)
insert into #test (col1,col2,col3) values (111,0,'1. jan 2007')
insert into #test (col1,col2,col3) values (111,0,'2. jan 2007')
insert into #test (col1,col2,col3) values (222,0,'4. jan 2007')
insert into #test (col1,col2,col3) values (222,0,'5. jan 2007')
insert into #test (col1,col2,col3) values (555,1,'6. jan 2007')
insert into #test (col1,col2,col3) values (666,0,'6. jan 2007')
select col1,col2,min(col3) as mincol3
from #test
group by col1,col2
Regards,
Palli
|||Oops !
Didn't see until too late that you posted your message twice and the other
thread had allready been answered.
Palli
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment