取表内前几条数据

mysql:
select * from table1 where 1=1 limit 10

sql server:
读取前10条:select top (10) * from table1 where 1=1
读取后10条:select top (10) * from table1 order by id desc
在sqlserver里面,如何读取按照某个排序,第5到10这五个记录
select top 6 * from table where id not in(select top 4 id from table)

oracle:
select * from table1 where rownum<=10
(效率不高)
select * from (select * from tb_user where rownum<=2*2) minus (select * from tb_user where rownum<=1*2)

select * from(select * from(select rownum no ,a.* from table1 a) where no>0) where rownum<=6;
rownum只能是小于,因为rownum是游标。必须把游标全读出来,才能通过no参数表示大于。

查询某表中的第30到40行的数据
select * from 表名 where 字段 in( select top 40 字段 from 表名 )and 字段 not in( select top
30 字段 from 表名)
或者
select top 10 * from 表名 where 字段 not in( select top 30 字段 from 表名)

查询一个表中存在重复的字段“字段1”
select DISTINCT 字段1 from 表名 having count(字段1)>1 group by 字段1
(并显示可能重复的次数)
select DISTINCT 字段1, count(字段1) As 次数 from 表名 having count(字段1)>1 group by 字段1

原文地址:https://www.cnblogs.com/tyf0422/p/2938766.html