回答編集履歴

2

追記

2020/11/02 09:20

投稿

sazi
sazi

スコア25327

test CHANGED
@@ -27,3 +27,69 @@
27
27
  and p.person_code = h3.person_code
28
28
 
29
29
  ```
30
+
31
+ 上記をイメージし易いような別な記述にすると、
32
+
33
+ ```SQL
34
+
35
+ SELECT p.person_name
36
+
37
+ , h1.used_date 代休, h2.used_date 有給, h3.used_date 怪我病欠
38
+
39
+ FROM PERSON p
40
+
41
+ left JOIN (
42
+
43
+ select * from HOLIDAY where holiday_code='1000'
44
+
45
+ ) h1
46
+
47
+ ON p.person_code = h1.person_code
48
+
49
+ left JOIN (
50
+
51
+ select * from HOLIDAY where holiday_code='2000'
52
+
53
+ ) h2
54
+
55
+ ON p.person_code = h2.person_code
56
+
57
+ left JOIN (
58
+
59
+ select * from HOLIDAY where holiday_code='3000'
60
+
61
+ ) h3
62
+
63
+ ON p.person_code = h3.person_code
64
+
65
+ ```
66
+
67
+ where条件で指定しようとすると、
68
+
69
+ ```SQL
70
+
71
+ SELECT p.person_name
72
+
73
+ , h1.used_date 代休, h2.used_date 有給, h3.used_date 怪我病欠
74
+
75
+ FROM PERSON p
76
+
77
+ left JOIN HOLIDAY h1
78
+
79
+ ON p.person_code = h1.person_code
80
+
81
+ left JOIN HOLIDAY h2
82
+
83
+ ON p.person_code = h2.person_code
84
+
85
+ left JOIN HOLIDAY h3
86
+
87
+ ON p.person_code = h3.person_code
88
+
89
+ where (h1.holiday_code='1000' or h1.holiday_code is null)
90
+
91
+ and (h2.holiday_code='2000' or h2.holiday_code is null)
92
+
93
+ and (h3.holiday_code='3000' or h3.holiday_code is null)
94
+
95
+ ```

1

訂正

2020/11/02 09:20

投稿

sazi
sazi

スコア25327

test CHANGED
@@ -16,13 +16,13 @@
16
16
 
17
17
  left JOIN HOLIDAY h2
18
18
 
19
- ON h1.holiday_code='2000'
19
+ ON h2.holiday_code='2000'
20
20
 
21
21
  and p.person_code = h2.person_code
22
22
 
23
23
  left JOIN HOLIDAY h3
24
24
 
25
- ON h1.holiday_code='3000'
25
+ ON h3.holiday_code='3000'
26
26
 
27
27
  and p.person_code = h3.person_code
28
28