楼主: luling2010
2367 8

proc sql 嵌套式查询 [推广有奖]

  • 5关注
  • 11粉丝

高级会员

院士

37%

还不是VIP/贵宾

-

威望
1
论坛币
11803 个
通用积分
1733.0055
学术水平
12 点
热心指数
33 点
信用等级
9 点
经验
248578 点
帖子
2054
精华
0
在线时间
3736 小时
注册时间
2006-4-24
最后登录
2022-12-8

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
各位大神:
    小弟请教一题,
    proc sql;
          create table temp as
          select id,
                   sum(price) as income
         from a
         where  id in (select id from b)
         quit
;
    感觉这样做总是很慢,即使B表中的记录条数很少,请问是怎么回事?
二维码

扫码加我 拉你入群

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

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

关键词:proc sql ROC sql Select Income

回帖推荐

webgu 发表于2楼  查看完整内容

子查询语句比JOIN低效。 proc sql; create table temp as select id, sum(price) as income from b left join a on b.id=a.id; quit;
沙发
webgu 发表于 2013-3-4 10:02:32 |只看作者 |坛友微信交流群
子查询语句比JOIN低效。

proc sql;
          create table temp as
          select id, sum(price) as income
          from b left join a on
          b.id=a.id;
quit;
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

藤椅
冰雨狼 发表于 2013-3-4 12:04:09 |只看作者 |坛友微信交流群
ls正解

使用道具

板凳
luling2010 发表于 2013-3-4 13:20:22 |只看作者 |坛友微信交流群
感谢webgu的解答!再追一下,一般子查询和JOIN的用途一样不,是不是涉及到子查询的都可以用JOIN替代?

使用道具

报纸
webgu 发表于 2013-3-4 16:47:37 |只看作者 |坛友微信交流群
我还没有涉及过大数据量的操作,没有体会到这两种方法的差别。只是哪个用来顺手就用哪个了。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

地板
luling2010 发表于 2013-3-4 20:00:34 |只看作者 |坛友微信交流群
嗯,谢谢楼主!

使用道具

7
Bridgenc 发表于 2013-3-4 20:22:32 |只看作者 |坛友微信交流群
Data step is much faster than proc sql for large dataset, but have to sort first

使用道具

8
bobguy 发表于 2013-3-5 07:51:36 |只看作者 |坛友微信交流群
It is not that bad. But the join lightly beats a subquery. The inner join is the best.

data a;
   do id=1 to 1e6;
      price=id;
          output;
          output;
        end;
run;

data b;
   do id=100000 to 200000;
          output;
        end;
run;

proc sql _method stimer;
          create table temp as
          select id,
                   sum(price) as income
         from a
         where  id in (select id from b)
                 ;
         quit;

proc sql _method stimer;
          create table temp as
          select b.id, sum(price) as income
          from b left join a on
          b.id=a.id;
quit;


proc sql _method stimer;
          create table temp as
          select b.id, sum(price) as income
          from b inner join a on
          b.id=a.id;
quit;

使用道具

9
luling2010 发表于 2013-3-5 10:18:54 |只看作者 |坛友微信交流群
bobguy 发表于 2013-3-5 07:51
It is not that bad. But the join lightly beats a subquery. The inner join is the best.

data a;
Learn a lot! Thank you very much!

使用道具

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

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

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

GMT+8, 2024-4-28 12:28