回答編集履歴

2

かいぎょう

2019/09/30 08:13

投稿

yambejp
yambejp

スコア114845

test CHANGED
@@ -66,7 +66,11 @@
66
66
 
67
67
  select id,category from tbl as t1
68
68
 
69
+ where not exists(
70
+
71
+ select 1 from tbl
72
+
69
- where not exists(select 1 from tbl where category=t1.category and d>t1.d having count(*)>=3)
73
+ where category=t1.category and d>t1.d having count(*)>=3)
70
74
 
71
75
  ) as sub)
72
76
 

1

ちょうせい

2019/09/30 08:13

投稿

yambejp
yambejp

スコア114845

test CHANGED
@@ -56,23 +56,19 @@
56
56
 
57
57
 
58
58
 
59
- これ以外のデータを削除するので、条件をひっくり返してサブクエリにいれる
59
+ これ以外のデータを削除するので、サブクエリにいれてnotで引っ掛け
60
60
 
61
61
  ```SQL
62
62
 
63
63
  delete from tbl
64
64
 
65
- where (id,category) in (select * from(
65
+ where not (id,category) in (select * from(
66
66
 
67
67
  select id,category from tbl as t1
68
68
 
69
- where not exists(
69
+ where not exists(select 1 from tbl where category=t1.category and d>t1.d having count(*)>=3)
70
70
 
71
- select 1 from tbl
72
-
73
- where category=t1.category and d>t1.d having count(*)<3)
74
-
75
- ) as sub);
71
+ ) as sub)
76
72
 
77
73
  ```
78
74