码迷,mamicode.com
首页 > 数据库 > 详细

SQL语句练习

时间:2018-07-22 22:28:29      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:查询   练习   ...   sql查询   limit   order by   bsp   语句   row   

查询21-30条的数据库
MySql查询
select * from table LIMIT 20,10

SqlServer查询

2.1先根据ID升序 查询前30条记录信息,再将查询的结果根据ID降序 查询前20条记录

Select * from (select top 20 * from (select top 30 * from 表名 order by ID)t1 order by ID desc  )t2 order by ID
2.2先将查询出前10条记录信息,然后将这10条信息从结果集中剔除掉
select top 10 * from 表名 where id not in (select top 10 id from 表名 order by id asc )order by ID
先查询出前10条记录最大的ID,然后再查询出>ID的前10条记录信息
select top 10 * from 表名 where ID >(select max(ID) from (select top 10 ID From 表名 order by ID) t1) order by ID
Oracle查询
select * from (select rownum no,* from 表名 where rownum <=30 )where no >20
 
如何删掉数据重复,仅仅保留一条数据
Delet from table t where (t.字段,t.字段2,...,t.字段n)in (SELECT 字段1,字段2,...,字段n from table group by 字段1,字段2,...,字段n having count(*)>1)and rowid not in(select min(rowid) from table group by 字段1,字段2,...,字段n having count(*)>1)
 
 

SQL语句练习

标签:查询   练习   ...   sql查询   limit   order by   bsp   语句   row   

原文地址:https://www.cnblogs.com/nanguoyezi/p/9351558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!