
写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的
Case1:selecttop10*fromT_ApwhereIdnotin(selecttop30IdfromT_Ap)Case2:selecttop10*fromT_...
Case1: select top 10 * from T_Ap where Id not in (select top 30 Id from T_Ap)
Case2: select top 10 * from T_Ap where Id>(select max(Id) from(select top 30 Id from T_Ap)as T_Ap)
Case2中sql语句select max(Id) from(select top 30 Id from T_Ap)as T_Ap 查询出的数据为表T_AP的最大id值并非是头30行的数据!导致最终结果查询为空。这是怎么回事呢????
下图为Case1 查询出的数据。 展开
Case2: select top 10 * from T_Ap where Id>(select max(Id) from(select top 30 Id from T_Ap)as T_Ap)
Case2中sql语句select max(Id) from(select top 30 Id from T_Ap)as T_Ap 查询出的数据为表T_AP的最大id值并非是头30行的数据!导致最终结果查询为空。这是怎么回事呢????
下图为Case1 查询出的数据。 展开
1个回答
展开全部
有可能是因为子查询结果集别名和表名相同造成的。改一下子查询结果集的别名试试呢,不要as T_Ap,as另外一个名字
更多追问追答
追问
一样的。。。。
追答
这不太可能。
你试一下select top 30 Id from T_Ap和select top 30 Id from T_Ap order by id结果是不是相同
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询