新建临时表字段id,向临时表里插入1,2,3,4,5,6 if object_id('tempdb..#test') is not null drop table #test create table #test(id int)insert into #test(id)values(1),(2),(3),(4),(5),(6) declare @page int---当前页面declare @rows int---页面大小set @page=2set @rows=3 ---------当前页面为…
------ row number ---------- ------ row number ---------- declare @pageSize int,@pageIndex int ; select * from ( SELECT ROW_NUMBER() OVER(ORDER BY Byod_ZZFP.ID DESC) as rowID ,Byod_ZZFP. )T ) and rowID <= @pageSize * (@pageIndex)) order by ID desc --…
方法一: --分页方法一 OrderID,CustomerID, EmployeeID,OrderDate,ShippedDate,ShipName,ShipAddress,Freight from [Orders] OrderID from [Orders] order by OrderID) 方法二: --分页方法二 select * from (select OrderID,CustomerID, EmployeeID,OrderDate,ShippedDate,ShipName,Ship…
-- 3000 page(从1开始) 10 pagesize -- 方法1(效率不高): SELECT TOP 10 * FROM [xxx].[oooo] WHERE id NOT IN (SELECT TOP (10*(3000-1)) id FROM [xxx].[oooo] ORDER BY createtime DESC)ORDER BY createtime DESC; 方法2(效率高): SELECT TOP 10 * FROM (SELECT ROW_NUMBER() OVER…
最近有项目反应,在服务器CPU使用较高的时候,我们的事件查询页面非常的慢,查询几条记录竟然要4分钟甚至更长,而且在翻第二页的时候也是要这么多的时间,这肯定是不能接受的,也是让现场用SQLServerProfiler把语句抓取了上来. 用ROW_NUMBER()进行分页 我们看看现场抓上来的分页语句: select top 20 a.*,ag.Name as AgentServerName,,d.Name as MgrObjTypeName,l.UserName as userName from…
一 原因一 oracle默认为每个表生成rowmun,rowid字段,这些字段我们称之为伪列 测试表 CREATE TABLE A ( AID NUMBER() primary key, ANAME VARCHAR2() ) insert into A values(,'甲骨文'); insert into A values(,'微软'); insert into A values(,'ioe'); insert into A values(,'iBe'); insert into A valu…
--分页三种方法--第一种 ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs 大于pagesize*pageindex,少于等于pagesize*(pageindex+1) --效率最高SELECT * FROM Sys_User AS ALEFT JOIN(SELECT ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs ,ID FROM dbo.Sys_User --效率 次之) AS B ON A.ID = B.…
using Maticsoft.Common; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Maticsoft.Web.cest { public partial class WebForm1 : Syste…
第一种: SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM table_name) A ) ; 第二种: SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A) AND 10; 建议用第一种.…
1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1 要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量. 2.SELECT INTO FROM语句 语句形式为:SELECT vale1, value2 into Table2 from Table1 要求目标表Table2不…
SQL SERVER2012在ORDER BY 子句中加入了新元素offset,允许用户在排序完成的结果集中自定义输出行范围,大大简化了分页SQL的书写方式和效率. SQL SERVER2012在ORDER BY 子句中加入了新元素offset,允许用户在排序完成的结果集中自定义输出行范围,大大简化了分页SQL的书写方式和效率.以下是与以前的两种分页方式的简单对比 use master go set nocount on go set showplan_text on go --2012的OFF…