»çÀÌÆ®¸Ê  |  Contact Us
 
Ȩ > SAS Stories > SAS Áú¹®°ú ´äº¯
sql join °ü·Ã 2018.10.22
Àüº¸¹è 814 0
http://www.mysas.co.kr/sas_club/b_answer.asp?b_no=11021&gotopage=7&con=subject&keyword=&cmd=content&bd_no=6&gubun=

id id year 
1 1 2004 
2 1 2005 
3 3 2004 

À§ µ¥ÀÌÅ͸¦ "test" ¶ó°í ÇßÀ» ¶§, ¾Æ·¡ Äڵ带 ½ÇÇàÇØ º¸½Ã¸é ¿øÇϽô °á°ú´Â ³ª¿É´Ï´Ù. 
±ÞÈ÷ ÀÛ¼ºÇÏ´À¶ó Äڵ尡 ±â³×¿ä ¤Ð¤Ð 
µµ¿ò µÇ¼Ì±â¸¦ ¹Ù¶ø´Ï´Ù. 

proc sql; 
create table test11 as 
select id 
, id2 
, case when id = id2 then year else . end as year2 
, case when id ^= id2 then year else . end as year3 
from test 
quit; 

proc sql; 
create table test22 as 
select id 
, year2 as year 
from test11 
quit; 

proc sql; 
create table test33 as 
select id2 as id 
, year3 as year 
from test11 
where year3 ^= . 
quit; 

proc sql; 
create table work.test44 as 
select * from work.test22 
outer union corr 
select * from work.test33 

quit;  ​


---------------------------------------[ ¿ø ¹® ]---------------------------------------

 

sql¿¡¼­ A tableÀÇ id¸¦ ±âÁØÀ¸·Î B table¿¡¼­ µ¿ÀÏÇÑ id¿¡ ÇØ´çÇÏ´Â ¸ðµç °ªÀ» ´Ù °¡Á®¿À°í ½ÍÀºµ¥¿ä.. 

B Å×ÀÌºí¿¡¼­ id´Â °°Áö¸¸ ´Ù¸¥ Ä÷³ °ªÀÌ ´Ù¸¥ case¸¦ ¸ðµÎ °¡Á®¿À°í ½ÍÀ»¶§ ¾î¶»°Ô ½á¾ß ÇÒ±î¿ä?

a.id=b.id ·Î ÇÏ´Ï ´Ù¸¥ º¯¼ö°ªµéÀÌ ¿ÂÀüÈ÷ ´Ù ¾Èµé¾î¿Í¼­¿ä..

¾Æ·¡Ã³·³ ¸¸µé°í ½Í¾î¼­¿ä

id     id    year

1      1     2004

2      1    2005

3      3   2004

 

id  year

1  2004

1  2005

2

3  2004 

 
 
 
ÈÞ´ëÆù ¹øÈ£
ÈÞ´ëÆù ÀÎÁõ¹øÈ£
 
 ÁúÀǺô´õ¿¡¼­ 'Å×À̺í Á¶ÀÎ' ±â´É¸¸ ½ÇÇàÀÌ ¾ÈµË´Ï´Ù.
 ÁúÀǺô´õ¿¡¼­ 'Å×À̺í Á¶ÀÎ' ±â´É¸¸ ½ÇÇàÀÌ ¾ÈµË´Ï´Ù.