回答編集履歴
3
追記
test
CHANGED
@@ -21,3 +21,15 @@
|
|
21
21
|
where (select count(*) from X where user=t.user and attr in ('pretty', 'beauty'))=2
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
性能重視で考えると以下の記述も
|
26
|
+
|
27
|
+
```SQL
|
28
|
+
|
29
|
+
select user from x
|
30
|
+
|
31
|
+
group by user
|
32
|
+
|
33
|
+
having count(case when attr in ('pretty', 'beauty') then 1 end)=2
|
34
|
+
|
35
|
+
```
|
2
追記
test
CHANGED
@@ -9,3 +9,15 @@
|
|
9
9
|
```
|
10
10
|
|
11
11
|
ですね。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
(user,attr)で一意なら以下の様な記述でも同様な結果になります。
|
16
|
+
|
17
|
+
```SQL
|
18
|
+
|
19
|
+
select distinct user from X t
|
20
|
+
|
21
|
+
where (select count(*) from X where user=t.user and attr in ('pretty', 'beauty'))=2
|
22
|
+
|
23
|
+
```
|
1
訂正
test
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
select distinct user from X t
|
4
4
|
|
5
|
-
where exists(select 1
|
5
|
+
where exists(select 1 from X where user=t.user and attr ='pretty')
|
6
6
|
|
7
|
-
and exists(select 1
|
7
|
+
and exists(select 1 from X where user=t.user and attr ='beauty')
|
8
8
|
|
9
9
|
```
|
10
10
|
|