我对于SAS ADV的crackman 63题中第6题(Item 6)的B选项(注:原题正确答案是C),百思不得其解,求解答。原题和选项B附在最后
我想不通的点是:
为什么select avg (salary)这个次级的select是return 3个avg(按照crackman的解释)?
我还原了下这个次级的select,写了段code(如下),结果return的就是一个avg:7000
data pilots;
input id name $ jobcode $ salary@;
datalines;
001 Albert PT1 50000
002 Brenda PT1 70000
003 Carl PT1 60000
004 Donna PT2 80000
005 Edward PT2 90000
006 FLora PT3 100000
;
run;
data P2;
set pilots;
run;
proc sql;
select avg(P1.salary)
from work.pilots as P1, P2
where P1.jobcode=P2.jobcode;
quit;
下面是原题和B选项:
Item 6 of 63 Mark item for review
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?
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
;