create table test4
(
id int identity(1,1),
name varchar(100)
)
create table test4Score
(
test4id int,
score int
)
insert into test4(name)
select 'LeeWhoeeUniversity'
union all
select 'LeeWhoee'
union all
select 'DePaul'
insert into test4score(test4id,score)
select 1,100
union all
select 1,90
union all
select 1,90
union all
select 1,80
union all
select 2,90
union all
select 2,82
union all
select 2,10
SELECT * FROM test4
SELECT * FROM test4score
select * from test4 a
cross apply
(
select top 1 * from test4score where test4id=a.id order by score desc
) b
select * from test4 a
outer apply
(
select top 1 * from test4score where test4id=a.id order by score desc
) b
Sql中apply
最新推荐文章于 2024-09-11 15:08:21 发布