当前位置:编程学习 > C#/ASP.NET >>

一道试题

 写出一条Sql语句: 取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键, 注意:ID可能不是连续的。)
帮忙解决一下,谢谢 --------------------编程问答--------------------
select top 10 * 
  from table
 where id not in (select top 30 id
                    from table
                   order by id)
 order by id

--------------------编程问答-------------------- select top 10 * from [A] where id in (select top 40 id from [A] order by id desc) --------------------编程问答--------------------
引用 1 楼 llsen 的回复:
SQL codeselecttop10*fromtablewhere idnotin (selecttop30 idfromtableorderby id)orderby id



llsen终于出招了


我曾经也遇到过这道面试题,也是这样回答的,可是面试官不满意,问 如果有100W条数据呢,求方法: --------------------编程问答-------------------- 这题也算是很经典的题目了啊。
到处都有。呵呵

--------------------编程问答-------------------- up,一楼 --------------------编程问答-------------------- up --------------------编程问答-------------------- 不可连续在一楼这句该如何理解?我刚学.请指教 --------------------编程问答-------------------- 很经典的一道题,有点类似分页的语句.从而我联想到一到题,推荐给楼主。

例如:每页显示10条数据,而且按最新时间往后排.

select top 10 * from 表1 where uid = 登陆id and id not exits(select top 10*(当前页数-1) from 表1 where uid = 登陆id order by time desc) order by time desc --------------------编程问答-------------------- 先排序然后再取就行 --------------------编程问答--------------------

这是一道面试题吧:
(1)select top 10 * from table where id not in(select top 30 * from table)
(2)select identity(int,1,1) as newId,* into #temp from table
   select * from #temp where newId>=30 and newId<40

补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,