工资从高到底排序: select * from UserTable order by UserAlary desc。
查询前三条数据: select top 3 * from UserTable Order by UserAlary desc.
查询第5-10条的数据:select top 5* from UserTable where Id not in (select top 5 id from UserTable order by id desc) order by id desc.
2.抑制重复数据:
处理重复的年龄: select distinct UserAge from UserTable
PS注意:
如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中,否则会出现错误。
比如SQL语句:SELECT DISTINCT UserAge FROM
UserTable order by
UserAge ASC是可以正常执行的。但是如果SQL语句是: SELECT DISTINCT
UserAge FROM
UserTable order by id ASC是不能正确执行的,SQL语句修改成:
SELECT DISTINCT UserAge id FROM UserTable order by id ASC 可以正常执行。