1、创建测试表,
create table test_limit(id int ,value varchar(100))
2、插入测试数据,共6条记录;
insert into test_limit values (1,'v1')
insert into test_limit values (2,'v2')
insert into test_limit values (3,'v3')
insert into test_limit values (4,'v4')
insert into test_limit values (5,'v5')
insert into test_limit values (6,'v6')
3、查询表中全量数据,可以发现共6条数据,select * from test_limit t
4、编写语句,指定查询3条数据;
select * from test_limit limit 3
通过查询语句select * from user where id=1
我不知道你这个username指的是不是字段,如果是要取出表中某个字段的值。
可以通过select 字段名1,字段名2 ... from user where id=1。
-- MS sql server2005以上,ORACLE
select * from (
select row_number() over ( order by starttime asc) as rownum,* from steriworkrecord
where starttime between '2013-11-1' and '2013-12-31'
) a
where rownum between 2 and 10
-- 【注意( order by starttime asc)是你排序的方式asc升序,desc降序】
-- ORACLE还可以
select * from (
select rownum as n,* from steriworkrecord
where starttime between '2013-11-1' and '2013-12-31'
) a
where a.n between 2 and 10
-- MYSQL,postgreSQL似乎只能标量子查询
SELECT *FROM (
SELECT a.*,(
SELECT count(*) FROM steriworkrecordb WHERE b.ID<= a.ID) AS n
from steriworkrecorda
) ts
where ts.n between 2 and 10
-- 【注意b.ID<= a.ID 其中ID换成你的主键名称】
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)