全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1981 2
2016-10-27
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


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-11-5 23:25:27
the question has a bug,should add group by product_id in proc sql when sum sales
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-12-28 11:26:10
把 s.totalsales 的s去掉

Proc sql;
  Select p.product, totalsales
         From product as p
                left join (   select sum(sales) as totalsales
                              from sales as s
                              group by Product_id)
                on p.product_id=s.product_id;
quit;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群