590
社区成员
发帖
与我相关
我的任务
分享
select * from 表
不就是了么SELECT * FROM (SELECT *,ROW_NUMBER()OVER(PARTITION BY colum1 ORDER BY colum2) AS RN FROM tablename) AS T WHERE RN=1
--测试数据
if not object_id(N'Tempdb..#A') is null
drop table #A
Go
Create table #A([colum1] int,[colum2] int)
Insert #A
select 1,1 union all
select 1,2 union all
select 1,3 union all
select 2,1 union all
select 2,2 union all
select 2,3 union all
select 3,1 union all
select 3,2 union all
select 3,3
Go
--测试数据结束
Select [colum1],MIN([colum2]) AS [colum2] from #A GROUP BY [colum1]