全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2300 8
2015-06-25
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。
完全没有思路,求大神帮忙解答,30号要考advanced,谢谢!!!

二维码

扫码加我 拉你入群

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

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

全部回复
2015-6-26 07:26:39
这个就是先按照每个group求总和 然后union

这题主要是D是干扰项 因为sum(cost)后面没有sepcify一个变量名字 无法corr union到cost下面


二维码

扫码加我 拉你入群

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

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

2015-6-26 11:44:30
sas那个石家庄人 发表于 2015-6-26 07:26
这个就是先按照每个group求总和 然后union

这题主要是D是干扰项 因为sum(cost)后面没有sepcify一个变量名 ...
A里面也没有说sum(cost) as.....,所以这里为什么要specify变量名字呢?
还有一个问题,group by ID和 group by 1的区别在哪里?
谢谢!
二维码

扫码加我 拉你入群

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

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

2015-6-26 11:48:56
hailingkatherin 发表于 2015-6-26 11:44
A里面也没有说sum(cost) as.....,所以这里为什么要specify变量名字呢?
还有一个问题,group by ID和 g ...
A使用了 label= “Cost” 而且A是union 不是out union 只有out union才需要用corr来overlay名字一样的column

group by id 和 group by 1 是一回事   
1代表着 变量在select 语句中column的位置
二维码

扫码加我 拉你入群

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

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

2015-6-26 15:32:13
sas那个石家庄人 发表于 2015-6-26 11:48
A使用了 label= “Cost” 而且A是union 不是out union 只有out union才需要用corr来overlay名字一样的col ...
恩恩,谢谢!那麻烦看下下面的程序:
proc sql;
select product, type, sum(sales) as revenue
from one
group by product, type;
quit;
如果我想让显示出的内容是按product的正序和revenue的decreasing显示的话,
那A order by 1,3 desc
   B order by product, revenue desc
这个答案是选A,想问下为什么这里却不一样
二维码

扫码加我 拉你入群

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

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

2015-6-26 16:03:49
hailingkatherin 发表于 2015-6-26 15:32
恩恩,谢谢!那麻烦看下下面的程序:
proc sql;
select product, type, sum(sales) as revenue
能把原题发下吗 感觉AB应该都可以
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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