日期:2014-05-17  浏览次数:20535 次

查询语句执行顺序,求解释
select top 30 * from t where price>40 order by price
先取price>40再排序然后取前30条记录吗?

------解决方案--------------------
取price>40的记录,然后按price升序排序,取其前30条.
------解决方案--------------------
先where 再order by,然后在集合中选30条
------解决方案--------------------
select top 30 * from (select * from t where price>40) order by price
先取price>40再排序然后取前30条记录
------解决方案--------------------
不一定是“总是”,比如你没有top,那么最后是order by
------解决方案--------------------
select top 30 * from t where price>40 order by price

你说的是对的。

1、where条件price>40 先把符合要求的数据,选出来

2、对选出来的数据,进行排序 也就是  order by price

3、最后再选出30条,也就是 top 30