回答編集履歴
1
chousei
test
CHANGED
@@ -51,3 +51,67 @@
|
|
51
51
|
and num=t1.num);
|
52
52
|
|
53
53
|
```
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# 検証
|
58
|
+
|
59
|
+
まずグルーピング処理
|
60
|
+
|
61
|
+
```SQL
|
62
|
+
|
63
|
+
select num,count(distinct name) as cnt from tbl
|
64
|
+
|
65
|
+
group by num;
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
|num|cnt|
|
70
|
+
|
71
|
+
|--:|--:|
|
72
|
+
|
73
|
+
|1|1|
|
74
|
+
|
75
|
+
|2|1|
|
76
|
+
|
77
|
+
|3|2|
|
78
|
+
|
79
|
+
|4|2|
|
80
|
+
|
81
|
+
|5|2|
|
82
|
+
|
83
|
+
|6|3|
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
これを、cntが複数(>1)で絞り込む
|
88
|
+
|
89
|
+
```SQL
|
90
|
+
|
91
|
+
select num,count(distinct name) as cnt from tbl
|
92
|
+
|
93
|
+
group by num
|
94
|
+
|
95
|
+
having count(distinct name)>1
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
|num|cnt|
|
100
|
+
|
101
|
+
|--:|--:|
|
102
|
+
|
103
|
+
|3|2|
|
104
|
+
|
105
|
+
|4|2|
|
106
|
+
|
107
|
+
|5|2|
|
108
|
+
|
109
|
+
|6|3|
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
ここまでがカッコ内の処理
|
114
|
+
|
115
|
+
ここで抽出されるnumと、外側のテーブルnumを
|
116
|
+
|
117
|
+
where existsを使うと絞込める
|