欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

SQLSERVER中FIRST_VALUE和LAST_VALUE

程序员文章站 2024-02-04 09:49:22
...

WITH test as ( select '乐可乐可的部落格' as name,10 as score UNION ALL select '乐可乐可的部落格',15 UNION ALL select '乐可乐可的部落格',20 UNION ALL select '微软认证',30 UNION ALL select '微软认证',40 UNION ALL select '微软认证',40 ) selec

WITH test

as

(

select '乐可乐可的部落格' as name,10 as score

UNION ALL

select '乐可乐可的部落格',15

UNION ALL

select '乐可乐可的部落格',20

UNION ALL

select '微软认证',30

UNION ALL

select '微软认证',40

UNION ALL

select '微软认证',40

)

select name,score

,FIRST_VALUE(score)over(order by name) as fst

,LAST_VALUE(score)over(order by name) as Lst

from test