针对面试日记(1)分析

面试日记(1):http://www.cnblogs.com/GoGoagg/archive/2006/02/23/335972.html

两个sql语句都是正确的,在执行效率又咋样呢?

此处使用pubs数据库中的sales表来模拟

变换下输出:获得相同订单数量的title_id

语句类似:

Sql
select qty ,title_id from sales where qty in
(
Select qty from sales group by qty having count(qty) > 1
)
order by qty ,title_id

select qty ,title_id from sales where qty in
(
select a.qty from sales a,sales b
where a.qty = b.qty and a.title_id <> b.title_id
)
order by qty ,title_id

此点浏览执行效率:

从上图简单看出执行效率的分布

当然,索引、排序也有一定的因素

在实际的应用需要注意

posted @ 2010-08-09 10:16  西就东城  阅读(180)  评论(0编辑  收藏  举报