楼主: wenling15
2265 5

[问答] sas adv 63 question: can anybody help me to explain how to answer? Thanks [推广有奖]

  • 1关注
  • 0粉丝

硕士生

71%

还不是VIP/贵宾

-

威望
0
论坛币
722 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
10790 点
帖子
119
精华
0
在线时间
180 小时
注册时间
2015-8-19
最后登录
2018-2-28

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
The table WORK.PILOTS contains the following data:

   WORK.PILOTS

   Id   Name     Jobcode  Salary
   —  ——   ——-  ——
   001  Albert   PT1       50000
   002  Brenda   PT1       70000
   003  Carl     PT1       60000
   004  Donna    PT2       80000
   005  Edward   PT2       90000
   006  Flora    PT3      100000

The data set was summarized to include average
salary based on jobcode:      

   Jobcode  Salary     Avg     
   ——-  ——   —–     
   PT1       50000   60000     
   PT1       70000   60000     
   PT1       60000   60000     
   PT2       80000   85000     
   PT2       90000   85000     
   PT3      100000  100000     

Which SQL statement could NOT generate
this result?
        A.
select
   Jobcode,  
   Salary,   
   avg(Salary) label=\’Avg\’     
from WORK.PILOTS
group by Jobcode
order by Id  
;     

     B.
select
   Jobcode,  
   Salary,   
   (select avg(Salary)
   from WORK.PILOTS as P1      
   where P1.Jobcode=P2.Jobcode) as Avg  
from WORK.PILOTS as P2
order by Id  
;     

     C.
select
   Jobcode,  
   Salary,   
   (select avg(Salary)
   from WORK.PILOTS   
   group by Jobcode) as Avg   
from WORK.PILOTS
order by Id  
;     

     D.
select
   Jobcode,  
   Salary,   
   Avg
from  
   WORK.PILOTS,
  (select   
      Jobcode as Jc,   
      avg(Salary) as Avg
   from WORK.PILOTS   
   group by 1)
where Jobcode=Jc
order by Id  

二维码

扫码加我 拉你入群

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

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

关键词:question anybody explain Answer thanks following question anybody average include

沙发
lorpercon 发表于 2015-9-30 10:33:25 |只看作者 |坛友微信交流群
这题应该选C吗?感觉C不对。

使用道具

藤椅
lorpercon 发表于 2015-9-30 10:38:33 |只看作者 |坛友微信交流群
如果答案C选错的话请忽略我一下回答。
A 最正常的coding了,group by算每组的和。
B 最***coding, 是把一个表当成两个表,要问为啥这样,我觉得还是因为C不可以 C in line里已经选择了这个Data set,括号外面又是这个data set,一般这样的code都是错的 (个人经验,欢迎敲转)所以要写成B这种***的code
C 错,原因见上。
D 括号select里面相当于产生了一个dataset,和work pilots 并列,所以没问题。

说错了别打我

使用道具

板凳
wenling15 发表于 2015-9-30 23:29:04 |只看作者 |坛友微信交流群
crackman said it was C. I would like to read more about it. Which chapter I should read for this question
Thanks

使用道具

报纸
zhuosheng 发表于 2015-10-1 02:09:37 |只看作者 |坛友微信交流群
you should read summarizing and grouping data under proc sql programming.
a)as text states in the book, if a select clause contains summary functions and additional columns outside of summary functions, calculates a single value for the entire table or, if groups are specified, for each group, and displays all rows of output with the single or grouped value(s) repeated. Hence, A) can generate the printed result.

b)here is what i understand: SAS reads jobcode,salary from  P2(work.pilots) into PDV, then it comes to (select avg(salary) ) part, it will read back the jobcode value which is already read in PDV to identify the corresponding avg(salary)  value because p1.jobcode=p2.jobcode is presented. although it can generate the same result, it requires more resource, because it calculates the avg every time;

c)similar to B), but it is missing the where statement.
d)it is like divided into two tables, one is work.pilots, another one has only one column, the average values based on jobcode, and then uses join.

maybe i don't get it all right, but hopefully it can give you a hint.

cheers
Jack

使用道具

地板
wenling15 发表于 2015-10-1 03:36:15 |只看作者 |坛友微信交流群
Thank you so much, Jack

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-3 00:55