`
backspace
  • 浏览: 133698 次
文章分类
社区版块
存档分类
最新评论

sql语句查询出表里的第二条、第三条记录(附加多个条件)

 
阅读更多

1、查询所有数据

use MengYou_SQL
select * 
from pifa_Company 
where gs_passed=1 and on_top=1 and  gs_bigclass=25 
order by gs_add_date desc

 

2、查询第一条数据

use MengYou_SQL
select top 1 * 
from pifa_Company 
where gs_passed=1 and on_top=1 and  gs_bigclass=25 
order by gs_add_date desc

 

3、查询第二条、第三条数据

use MengYou_SQL
select top 2 * 
from pifa_Company 
where gs_passed=1 and on_top=1 and  gs_bigclass=25 
and gs_id not in( select top 1 gs_id from pifa_Company where on_top=1 and  gs_bigclass=25 and gs_passed=1  order by gs_id desc)
order by gs_add_date desc

 

4、实现的效果图

3
3
分享到:
评论
1 楼 wuchsh2013 2013-06-15  
数据量大的时候效率低哦。

相关推荐

Global site tag (gtag.js) - Google Analytics