在oracle中有一資料表exam_result(成績記錄表),
表中的一條記錄描述了「某個班某個學生某次考試的成績"
create table exam_result
( id number(10) not null, --主鍵
classid number(10) not null, -- 班級id,關聯到班級表
userid number(10) not null, --使用者id,關聯到使用者表
examid number(10) not null, --試卷id,關聯到試卷表
result number(3) --成績
)現在要求統計完成了試卷id為1,2,3的成績的前3名
即完成了試卷id為1的前3名,完成了試卷id為2的前3名,完成了試卷id為3的前3名
sql server 中分組取前n條記錄的實現:
分組後取前N條
這種題目面試中經常出現,記錄一下 首先建表 create table students id int 11 not null auto increment comment 學號 clss id varchar 2 default null comment 班級id stu name varchar ...
SQL查詢每個分組的前N條記錄
if object id tempdb.dbo.t is not null drop table t create table t id varchar 3 gid int,author varchar 29 title varchar 39 date datetime insert into t ...
SQL查詢每個分組的前N條記錄
在寫乙個儲存過程中,遇到了乙個問題,自己寫的 sql總是執行效率太低,於是上網搜尋,學到了乙個新招,都怪自己平時不愛學習啊,不過這個語法真的很厲害。需求 取乙個表中每個 id的最新三條資料 按照更新時間倒序取 select from t as t where 3 select count from ...