楼主: lovedieer
2014 2

[问答] a question about sas adv new questions [推广有奖]

  • 0关注
  • 1粉丝

已卖:18份资源

硕士生

60%

还不是VIP/贵宾

-

威望
0
论坛币
11 个
通用积分
2.0724
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
17239 点
帖子
146
精华
0
在线时间
201 小时
注册时间
2009-4-22
最后登录
2022-9-12

楼主
lovedieer 发表于 2016-10-27 02:47:33 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
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


二维码

扫码加我 拉你入群

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

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

关键词:questions question Quest tions About question about

沙发
lovexialulu 发表于 2016-11-5 23:25:27 来自手机
the question has a bug,should add group by product_id in proc sql when sum sales

藤椅
bruinwalk 发表于 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;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-27 08:47