回答編集履歴

1

調整

2019/04/02 05:05

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -30,9 +30,15 @@
30
30
 
31
31
  (7,3,'2019/03','2019-03-20 03:00:00'),
32
32
 
33
- (8,3,'2019/02','2019-02-01 04:00:00');
33
+ (8,3,'2019/02','2019-02-01 04:00:00'),
34
+
35
+ (9,4,'2019/03','2019-04-01 05:00:00'),
36
+
37
+ (10,5,'2019/03','2019-04-02 06:00:00');
34
38
 
35
39
  ```
40
+
41
+ ※insertデータを調整
36
42
 
37
43
 
38
44
 
@@ -55,3 +61,39 @@
55
61
  and wk_month='2019/03'
56
62
 
57
63
  ```
64
+
65
+
66
+
67
+ # 2行以上あるデータのみ
68
+
69
+ ```SQL
70
+
71
+ select * from tbl as t1
72
+
73
+ where not exists
74
+
75
+ (select 1 from tbl
76
+
77
+ where employee_id=t1.employee_id
78
+
79
+ and wk_month=t1.wk_month
80
+
81
+ and created_at<t1.created_at
82
+
83
+ )
84
+
85
+ and exists
86
+
87
+ (select 1 from tbl
88
+
89
+ where employee_id=t1.employee_id
90
+
91
+ and wk_month=t1.wk_month
92
+
93
+ having count(*)>1
94
+
95
+ )
96
+
97
+ and wk_month='2019/03'
98
+
99
+ ```