DB2更新前N條記錄的方法

2021-05-18 02:55:20 字數 462 閱讀 9292

由於db2中沒有類似oracle中的rownum函式,sql server中的top關鍵字,mysql中的limit關鍵字,所有需要曲線救國

示例**如下:

方法1:

update tablea set field1='value' where id in

(select id from( select row_number() over() as num,id from tablea ) ss where num>=1 and num<=100

)其中over() 中可以增加排序,如:over(order by id)

方法2:將查詢語句作為臨時表再更新

update  (select syn_time from inte***ce_status fetch first 100 rows only)  a 

set a.syn_time='2010-10-10 00:00:00'

分組取前n條記錄的實現

在oracle中有一資料表exam result 成績記錄表 表中的一條記錄描述了 某個班某個學生某次考試的成績 create table exam result id number 10 not null,主鍵 classid number 10 not null,班級id,關聯到班級表 user...

返回資料集的前n條記錄

size medium 對於mysql資料庫來說,想要實現只輸出部分行數的資訊,可以使用limit欄位 select from table name where limit 10 對於oracle 資料庫來說,想要實現只輸出部分行數的資訊,可以使用rownum欄位 select from table...

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 ...