-
Notifications
You must be signed in to change notification settings - Fork 0
/
week5_3수업(inline view_2).sas
80 lines (68 loc) · 1.99 KB
/
week5_3수업(inline view_2).sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*5_3 code 1*/
proc sql;
select Destination
,avg(Delay) as average
format = 3.0 label = 'Average Delay'
,min(Delay) as min
format = 4.0 label = 'Minimum Delay'
,max(Delay) as max
format = 3.0 label = 'Maximum Delay'
from airline.flightdelays
group by Destination;
quit;
/*5_3 handling a complex qury*/
/*step 1*/
proc sql;
select EmpID
from airline.flightschedule
where Date = '04mar2000'd
and Destination = 'CPH';
quit;
/*step 2 staffmaster에서는 state를, payrollmaster에서는 category를 가져와
*/
proc sql;
select substr(p.JobCode, 1,2) as Jobcategory
,s.State
from airline.staffmaster as s, /*innner join*/
airline.payrollmaster as p
where s.EmpID = p.EmpID and s.EmpID in
(select EmpID /*step 1에서 만든 non-correlated 서브쿼리*/
from airline.flightschedule
where Date = '04mar2000'd
and Destination = 'CPH');
quit;
/*step3 : 위에서 만든 Jobcategory, State와 supervisor table의 Jobcategory, State 비교해서
Id가져오기 */
proc sql;
select EmpID
from airline.supervisors as m,
(select substr(p.JobCode, 1,2) as Jobcategory
,s.State
from airline.staffmaster as s, /*innner join*/
airline.payrollmaster as p
where s.EmpID = p.EmpID and s.EmpID in
(select EmpID /*step 1에서 만든 non-correlated 서브쿼리*/
from airline.flightschedule
where Date = '04mar2000'd
and Destination = 'CPH')) as c
where m.JobCategory = c.JobCategory
and m.State = c.State;
quit;
/*step 4 이제 EmpID로부터 staffmaster table의 이름을 가져와*/
proc sql;
select FirstName, LAstName
from airline.staffmaster where EmpID in
(select EmpID
from airline.supervisors as m,
(select substr(p.JobCode, 1,2) as Jobcategory
,s.State
from airline.staffmaster as s, /*innner join*/
airline.payrollmaster as p
where s.EmpID = p.EmpID and s.EmpID in
(select EmpID /*step 1에서 만든 non-correlated 서브쿼리*/
from airline.flightschedule
where Date = '04mar2000'd
and Destination = 'CPH')) as c
where m.JobCategory = c.JobCategory
and m.State = c.State);
quit;