Get the App
SLTechnology News&Howtos  ›  Database  › 

SqlServer basic series-- row_number () rank () dense_rank () SqlServer series notes

Shulou Source: shulou.com Published: 2022-06-01 14:39:57 10月01日 Update

create table A

(

Id int identity,

Name char(10)

)

create table B

(

Id int,

[SubJect] char(10),

Score int

)

--1. Search for the number of the top two in each subject No Name Subject Score

select * from (SELECT *,rn=ROW_NUMBER() OVER(PARTITION BY subject ORDER BY score desc)

FROM B) t where t.rn=3 AND a.rownum

Tags: Results queries scores names clauses grades data subjects second names line numbers restrictions foundations notes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Shulou Information Docker MySQL