Item 26 of 63 Mark item for review
Given the following SAS data sets:
WORK.VISIT1 WORK.VISIT2
Id Expense Id Cost
--- ------- --- ----
001 500 001 300
001 400 002 600
003 350
The following result set was summarized and
consolidated using the SQL procedure:
Id Cost
--- ----
001 300
001 900
002 600
003 350
Which of the following SQL statements was
most likely used to generate this result?
A.
select
Id,
sum(Expense) label='COST'
from WORK.VISIT1
group by 1
union all
select
Id,
sum(Cost)
from WORK.VISIT2
group by 1
order by 1,2
;
B.
select
id,
sum(expense) as COST
from
WORK.VISIT1(rename=(Expense=Cost)),
WORK.VISIT2
where VISIT1.Id=VISIT2.Id
group by Id
order by
Id,
Cost
;
C.
select
VISIT1.Id,
sum(Cost) as Cost
from
WORK.VISIT1(rename=(Expense=Cost)),
WORK.VISIT2
where VISIT1.Id=VISIT2.Id
group by Id
order by
Id,
Cost
;
D.
select
Id,
sum(Expense) as Cost
from WORK.VISIT1
group by Id
outer union corr
select
Id,
sum(Cost)
from WORK.VISIT2
group by Id
order by 1,2
亲测,此题选A; B,C两项错在 Order by 没有指定 ID COST是来自哪个table的;
D 错在加了 corr 选择项表明会displays all column that in comman plus 那些并非两个数据集都存在的column;
outer union corr 等价于 data set 步的 merge by 语句;词句若无 corr 选择项则 是争取选项。