一道sql面试题的解答
2010-06-24 11:04
204 查看
题目:
写出一条Sql语句:
取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键, 注意:ID可能不是连续的。)
解答(已测试):
1、假设ID是连续的:
select top 10 * from A where ID not in (select top 30 ID from A)
或
select * from A where ID between 31 and 40
2、假设ID是不连续的:
select top 40 * from A except select top 30 * from A
或
select top 10 * from A where ID > (select max(ID) from A where ID in (select top 30 ID from A))
或
select top 10 * from A where ID not in (select top 30 ID from A)
写出一条Sql语句:
取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键, 注意:ID可能不是连续的。)
解答(已测试):
1、假设ID是连续的:
select top 10 * from A where ID not in (select top 30 ID from A)
或
select * from A where ID between 31 and 40
2、假设ID是不连续的:
select top 40 * from A except select top 30 * from A
或
select top 10 * from A where ID > (select max(ID) from A where ID in (select top 30 ID from A))
或
select top 10 * from A where ID not in (select top 30 ID from A)
相关文章推荐
- 一道sql面试题的解答
- 一道sql面试题的多种解答
- 一道Oracle SQL面试题及解答
- SQL面试题总结、解答
- 关于一道谷歌面试题——丑数的解答
- 一道经典的sql面试题不同的写法
- 关于一道微软面试题(据称)“飞机问题”详细解答
- IBM一道面试题及解答
- 一道sql面试题
- 一道sql 关于pivot的面试题
- 一道SQL面试题(行列互换)
- 解答Google的一道面试题
- 一道sql面试题:translate()函数的应用
- 一道面试题及解答
- 一道有难度的SQL面试题!
- 解答Google的一道面试题 收藏
- 转载:解答Google的一道面试题
- 一道面试题的解答
- 一道看似简单的sql面试题(count,group by,distinct)
- 百度一道面试题的PHP解答