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