i saw this new question here, and i list my running results.
can somebody tell me which answer is correct?
一道新题
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 500
1002 .
1003 200
i run the program on SAS
15 Proc sql;
16 Select p.product,
s.totalsales
17 From product as p
18 left join (select sum(sales) as totalsales from sales as s)
19 on p.product_id=s.product_id;
ERROR:
Column totalsales could not be found in the table/view identified with the correlation name S.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
if i remove the s. from s.totalsale,
15 Proc sql;
16 Select p.product,
totalsales
17 From product as p
18 left join (select sum(sales) as totalsales from sales as s)
19 on p.product_id=s.product_id;
NOTE: The query requires remerging summary statistics back with the original data.
and output is :
product totalsales
1001 800
1001 800
1001 800
1002 .
1003 800
1003 800