select distinct 字段1,时间1,时间2 from 表 A where 时间1 = (select top 1 时间1 from 表 where 字段1 = A.字段1) and 时间2 = (select top 1 时间2 from 表 where 字段1 = A.字段1)
select 字段1,Max(时间1),Max(时间2) from 表 Group By 字段1
select * from 表 where 字段1 in select distinct 字段1 from 表)
select 字段1,时间1,时间2 from 表 我只想 字段1 显示的参数不重复,而允许时间1,时间2重复,怎么办 ------------------ 没说清楚啊,
create table #test(id int,dt1 varchar(10),dt2 varchar(10)) go insert into #test values(1,'20030506','20030511') insert into #test values(1,'20030506','20030511') insert into #test values(2,'20030506','20030523') insert into #test values(3,'20030506','20030511') insert into #test values(2,'20030505','20030501') insert into #test values(3,'20030506','20030511') insert into #test values(3,'20030507','20030511') go select id,max(dt1),max(dt2) from #test group by id
select distinct 字段1,max(时间1),max(时间1) from 表 group by 字段1或select distinct 字段1,min(时间1),min(时间1) from 表 group by 字段1
where 时间1 = (select top 1 时间1 from 表 where 字段1 = A.字段1)
and 时间2 = (select top 1 时间2 from 表 where 字段1 = A.字段1)
我只想 字段1 显示的参数不重复,而允许时间1,时间2重复,怎么办
------------------
没说清楚啊,
go
insert into #test values(1,'20030506','20030511')
insert into #test values(1,'20030506','20030511')
insert into #test values(2,'20030506','20030523')
insert into #test values(3,'20030506','20030511')
insert into #test values(2,'20030505','20030501')
insert into #test values(3,'20030506','20030511')
insert into #test values(3,'20030507','20030511')
go
select id,max(dt1),max(dt2) from #test group by id
,max(dt2) from #test group by id
select distinct 字段1,max(时间1),max(时间1) from 表 group by 字段1或select distinct 字段1,min(时间1),min(时间1) from 表 group by 字段1