SQL笔试基础

SQLSERVER服务器中,给定表table1 中有两个字段 ID、LastUpdateDate,ID表示更新的事务号,LastUpdateDate表示更新时的服务器时间,请使用一句SQL语句获得最后更新的事务号

答:网上答案为:Select ID FROM table1 Where LastUpdateDate = (Select MAX(LastUpdateDate) FROM table1),但可能存在LastUpdateDate有相同的情况,其实也可以排序top1,Select top 1 ID From table1 order by LastUpdateDate desc

写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的。

答:解1: select top 10 * from A where id not in (select top 30 id fromA Order By ID Asc) Order By ID Asc

解2: select top 10 * from A where id >(select max(id) from (select top30 id from A  Order By ID Asc)as A) Order By ID Asc

原文地址:https://www.cnblogs.com/fantaohaoyou/p/9385574.html