回答編集履歴
3
edit group by 削除
answer
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
film_category
|
10
10
|
where
|
11
11
|
category_id = 1
|
12
|
-
group by
|
13
|
-
film_id
|
14
12
|
)
|
15
13
|
select
|
16
14
|
title
|
2
edit
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
※未検証
|
3
3
|
|
4
4
|
```sql
|
5
|
-
with getCategoryFilmId(
|
5
|
+
with getCategoryFilmId as(
|
6
6
|
select
|
7
7
|
film_id
|
8
8
|
from
|
@@ -20,9 +20,9 @@
|
|
20
20
|
getCategoryFilmId.film_id=film.film_id
|
21
21
|
|
22
22
|
```
|
23
|
+
[WITH問い合わせ(共通テーブル式)](https://www.postgresql.jp/document/12/html/queries-with.html)
|
23
24
|
|
24
|
-
|
25
|
-
以下、若干勘違いしていた回答
|
26
25
|
---
|
26
|
+
--以下、若干勘違いしていた回答
|
27
27
|
ER図だけでは何とも言えず、テーブル定義次第なところもあるのですが、
|
28
28
|
必要なのは[GROUP BY ](https://www.postgresql.jp/document/12/html/queries-table-expressions.html#QUERIES-GROUP)ですかね。
|
1
edit
answer
CHANGED
@@ -1,2 +1,28 @@
|
|
1
|
+
既に出ている回答で解決可能そうですけど、別の組み方で。
|
2
|
+
※未検証
|
3
|
+
|
4
|
+
```sql
|
5
|
+
with getCategoryFilmId(
|
6
|
+
select
|
7
|
+
film_id
|
8
|
+
from
|
9
|
+
film_category
|
10
|
+
where
|
11
|
+
category_id = 1
|
12
|
+
group by
|
13
|
+
film_id
|
14
|
+
)
|
15
|
+
select
|
16
|
+
title
|
17
|
+
from
|
18
|
+
film
|
19
|
+
join getCategoryFilmId on
|
20
|
+
getCategoryFilmId.film_id=film.film_id
|
21
|
+
|
22
|
+
```
|
23
|
+
|
24
|
+
|
25
|
+
以下、若干勘違いしていた回答
|
26
|
+
---
|
1
27
|
ER図だけでは何とも言えず、テーブル定義次第なところもあるのですが、
|
2
28
|
必要なのは[GROUP BY ](https://www.postgresql.jp/document/12/html/queries-table-expressions.html#QUERIES-GROUP)ですかね。
|