楼主: luling2010
2757 8

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

  • 5关注
  • 11粉丝

高级会员

已卖:374份资源

院士

37%

还不是VIP/贵宾

-

威望
1
论坛币
11803 个
通用积分
1735.1083
学术水平
12 点
热心指数
33 点
信用等级
9 点
经验
248660 点
帖子
2048
精华
0
在线时间
3737 小时
注册时间
2006-4-24
最后登录
2024-10-18

楼主
luling2010 发表于 2013-3-4 09:44:31 |AI写论文

+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
拉您进交流群
GMT+8, 2025-12-29 17:52