sql分页的几种写法】的更多相关文章

一直想整理下关于sql分页的几种方法,今天终于有时间整理下了.闲话少说直接上sql,先创建一个测试库,测试表以及测试数据,sql语句如下: CREATE DATABASE DBTEST GO USE DBTEST GO --创建测试表 create table pagetest ( id int identity(1,1) not null, col01 int null, col02 nvarchar(50) null, col03 datetime null ) --100万记录集 耗时 3…
string Strsql = string.Format(@"select ee.DOCUMENTNO,ee.APPLICANTNAME,ee.COMPANY,ee.REQUESTTIME,ee.REQ_TITLE, ee.INCIDENT, (datediff(d,getdate(),STARTTIME)) STARTTIME,cc.STEPLABEL ,isNull((select distinct USERNAME from ORG_USER where LOGINNAME = subs…
sql语句有几种写法 1:SELECT * FROM tablename ORDER BY RAND() LIMIT 想要获取的数据条数: 2:SELECT *FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 想要获取的数据条数; 3:SELECT * FROM `table`  AS t1 JOIN (SELECT ROUND(RAND() * (SELECT M…
以前复制的创建sql函数比较乱,现在将我自己项目中的三种sql函数做下对比,一目了然: (1)表值函数——方法一:直接创建临时表,并返回临时表.优点:函数体中间可以直接申明临时变量,并做各种逻辑处理,最后只要将需要返回的数据插入临时表,并return结束语返回就ok了. (2)表值函数——方法二:直接返回表数据:缺点是:整个函数体中间不能申明临时变量,只能在一个查询语句中,做些逻辑处理,太坑了. (3)标量值函数——方法三:函数直接返回字符串,没啥可说的,功能太单一,胜在轻便简单. 一.FUNC…
1.使用Row_number() over(order by columnName)函数来作为标示分页(下面的例子都是以last_seen来排序的,要求取顺序为20-30行的数据) SELECT Username,real_filename,Row_number() over (order by last_seen desc) as rn INTO #tempTable from Allftplog SELECT * FROM #tempTable where rn between 20 and…
1.正常循环语句 declare @orderNum varchar(255)create table #ttableName(id int identity(1,1),Orders varchar(255))declare @n int,@rows intinsert #ttableName(orders) select orderNum from pe_Orders where orderId<50--select @rows=count(1) from pe_Ordersselect @r…
查询分页的几种Sql写法 摘自:http://www.cnblogs.com/zcttxs/archive/2012/04/01/2429151.html 1.创建测试环境,(插入100万条数据大概耗时5分钟). create database DBTest use DBTest --创建测试表 create table pagetest ( id int identity(1,1) not null, col01 int null, col02 nvarchar(50) null, col03…
服务器文档下载zip格式   刚好这次项目中遇到了这个东西,就来弄一下,挺简单的,但是前台调用的时候弄错了,浪费了大半天的时间,本人也是菜鸟一枚.开始吧.(MVC的) @using Rattan.Core.Utility;@{ string ButtonScript = string.Empty;}@if (Rattan.Basic.Globals.GetIsAuth(ViewBag.AuthValues, "QuickExport")){ ButtonScript = @"…
创建环境: create table pagetest ( id ,) not null, col01 int null, col02 ) null, col03 datetime null ) --100万记录集(大约耗时5min) declare @i int ) begin ) ),getdate() end 几种分页方式比较: --写法1,not in/top --每页50条,取第2015页数据 declare @begin_date datetime declare @end_date…
.net连接sql server的几种连接字符串的写法 1, 混合验证模式登录 server=电脑名 或 电脑IP;database=数据库名;uid=数据库登录名;password=数据库登录密码 2, windows 验证登录 Data Source=计算机名称或ip地址;Initial Catalog=数据库名称;Integrated Security=True…