没有主键?? select * from tablename a where col2=(select min(col2) from tablename where col1=a.col1) and col3=(select min(col3) from tablename where col1=a.col1 and col2=a.col2)
select O.col1,(select top 1 col2 from [table] where col1=O.col1) ,(select top 1 col2 from [table] where col1=O.col1) from [table] O group by O.col1
是这样的 select O.col1,(select top 1 col2 from [table] where col1=O.col1) ,(select top 1 col3 from [table] where col1=O.col1) from [table] O group by O.col1
select sn=identity(int,1,1),* into #t from [table] select a.col1,a.col2,a.col3 from #t a where sn=(select min(sn) from #t b where b.col1=a.col1) --取相同col1的第一行,这样好处就是不用担心其他列有重复的值
select * from tablename a
where col2=(select min(col2) from tablename where col1=a.col1)
and col3=(select min(col3) from tablename where col1=a.col1 and col2=a.col2)
,(select top 1 col2 from [table] where col1=O.col1)
from [table] O
group by O.col1
select O.col1,(select top 1 col2 from [table] where col1=O.col1)
,(select top 1 col3 from [table] where col1=O.col1)
from [table] O
group by O.col1
select a.col1,a.col2,a.col3 from #t a where sn=(select min(sn) from #t b where b.col1=a.col1) --取相同col1的第一行,这样好处就是不用担心其他列有重复的值