一道新题
left join and in-line view
Product
Product_id Product
1 1001
2 1002
3 1003
Sales
Product_id Sales
3 100
1 200
5 100
1 200
3 100
1 100
Procsql;
Select p.product s.totalsales
From product as p
left join (
select sum(sales) as totalsales
from sales as s)
on p.product_id=s.product_id;
quit;
What is the output?
运行后结果应该是
Answer:
Product Totalsales
1001 700
1002 700
1003 700
因为 select sum(sales) as totalsales 出来的结果是一个数值700,表product跟起左连接的结果就是每个观测都多了一个列数据700.这个时候的on语句没有起作用。
|