猿问

sql 两种 join写法性能?

A:
select a.account_number, t.sales,t.time
from Account a
join
(
    select account_id, SUM(sales) sales, min(trans_time) time
    from trans
    group by account_id
    having sum(sales)>1000
) t on a.account_id=t.account_id

B:
select a.account_number, SUM(t.sales) sales, min(t.trans_time) time
from Account a
JOIN  trans  t on a.account_id=t.account_id  GROUP BY account_number  having sum(t.sales)>1000

数据量大的话A和B两种写法性能有区别吗?  

一只甜甜圈
浏览 521回答 3
3回答

湖上湖

  自己执行做个比较吧

叮当猫咪

建议不要用子查询。费时
随时随地看视频慕课网APP

相关分类

SQL Server
我要回答