楼主: hailingkatherin
2367 8

一道关于union的题目,求助! [推广有奖]

  • 0关注
  • 0粉丝

已卖:13份资源

硕士生

82%

还不是VIP/贵宾

-

威望
0
论坛币
277 个
通用积分
0
学术水平
1 点
热心指数
5 点
信用等级
1 点
经验
164 点
帖子
126
精华
0
在线时间
87 小时
注册时间
2015-1-18
最后登录
2016-5-15

楼主
hailingkatherin 发表于 2015-6-25 21:34:13 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

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

二维码

扫码加我 拉你入群

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

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

关键词:Union NIO consolidated consolidate summarized

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

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


藤椅
hailingkatherin 发表于 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的区别在哪里?
谢谢!

板凳
sas那个石家庄人 发表于 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的位置

报纸
hailingkatherin 发表于 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,想问下为什么这里却不一样

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

7
hailingkatherin 发表于 2015-6-26 16:18:39
sas那个石家庄人 发表于 2015-6-26 16:03
能把原题发下吗 感觉AB应该都可以
原题

8
sas那个石家庄人 发表于 2015-6-26 16:26:49
hailingkatherin 发表于 2015-6-26 16:18
C 把orderby给挤在一起了。。。 我当初也不相信有这么狗血的选项。。。

9
hailingkatherin 发表于 2015-6-26 16:30:41
sas那个石家庄人 发表于 2015-6-26 16:26
C 把orderby给挤在一起了。。。 我当初也不相信有这么狗血的选项。。。
啊我还以为是印刷错误,谢谢啦!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 08:24