1.有唯一項字段(例如id)
SELECT top 分頁大小 * FROM 表名 where id not in (select top (分頁大小*(第幾頁-1)) id from 表名 where 搜索字段1='aaa' and 搜索字段2='bbb' order by 排序字段) and 搜索字段1='aaa' and 搜索字段2='bbb order by 排序字段名;
SELECT TOP {page_size} * from {table} WHERE id NOT IN (SELECT TOP {start} id from {table} {('where' + where) if filters else ''} {orders}) {('and' + where) if filters else ''} {orders}
例:
SELECT top 10 * FROM ACstat where id not in (select top 0 id from Future.dbo.ACstat where brokername = '國元期貨' order by brokerid,ac) and brokername = '國元期貨' order by brokerid,ac;
2.可以沒有唯一項字段
SELECT * FROM (SELECT *,ROW_NUMBER() OVER (order by 排序字段) AS RowNo FROM 表名 where 搜索字段1='aaa' and 搜索字段2='bbb') AS A WHERE RowNo>(分頁大小*(第幾頁-1)) and RowNo<=(分頁大小*第幾頁) where 搜索字段1='aaa' and 搜索字段2='bbb'
SELECT * FROM (SELECT *,ROW_NUMBER() OVER ({orders}) AS RowNo FROM LogRecord.dbo.PythonPosition {('where' + where) if fields else ''}) AS A WHERE RowNo>{start} and RowNo<={end} {('and' + where) if fields else ''}
例:
SELECT * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY updatetime desc) AS RowNo FROM dbo.python_position where symbol='a') AS A WHERE RowNo>10 and RowNo<=20 and symbol='a';
浙公網安備 33010602011771號