CREATE TABLE [dbo].[test1](
    [program_id] [int] NULL,
    [person_id] [int] NULL
) ON [PRIMARY]

/*查询每组分组中第一条记录*/
select * from test1 as a
where a.person_id in 
( select  top 1 person_id from test1
where program_id = a.program_id);

select * from (  
   select ROW_NUMBER() over(partition by program_id order by person_id) as num,* from test1) as t
   where num=1

 

相关文章:

  • 2022-02-27
  • 2021-05-02
  • 2021-07-18
  • 2021-11-28
  • 2021-11-17
  • 2021-06-24
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
相关资源
相似解决方案