SQL分页语句
编码过程中遇到的SQL分页情况,总结:
从数据库表中第M条记录开始检索N条记录
MySQL:
先查询分页,然后排序:
select * from (select * from student limit 5,2) pageTable order by id desc ;
先排序,然后查询分页:select * from student order by id desc limit 5,2 ;
Oracle:
SELECT * from (SELECT ROWNUM r,t1.* from 表名称 t1 where rownum < M + N) pageTable where t2.r >= M;
SELECT * from (SELECT ROWNUM r,s.* from student s where rownum < 7) pageTable where t2.r >= 5
相关文档:
--聚合函数
use pubs
go
select avg(distinct price) --算平均数
from titles
where type='business'
go
use pubs
go
select max(ytd_sales) --最大数
from titles
go
use pubs
go
select min(ytd_sales)& ......
机器情况
p4: 2.4
内存: 1 G
os: windows 2003
数据库: ms sql server 2000
目的: 查询性能测试,比较两种查询的性能
SQL查询效率 step by step
-- setp 1.
-- 建表
create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick varchar(50) not null default '',
classid int not nul ......
SELECT DISTINCT '['+user_name(b.uid)+'].['+b.name+']' AS 对象名,b.type AS 类型
from sysdepends a,sysobjects b
WHERE b.id=a.depid
AND a.id=OBJECT_ID('过程名');
EXEC SP_DEPENDS '过程名'; ......
今天用time Like '2008-06-01%'语句来查询该天的所有数据,被提示语句错误。查了一下才发现该模糊查询只能用于String类型的字段。
自己也查阅了一些资料。关于时间的模糊查询有以下三种方法:
1.Convert转成String,在用Like查询。
select * from table1 where c ......