回答編集履歴
1
質問に書かれたテーブルに従ってSQLを修正しました。
answer
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
項目名はすべて小文字なのですね。
|
2
|
+
また、男性は男性の平均年齢なのでasobi_a.sex = '1'ですね。
|
1
|
-
|
3
|
+
質問にあるデータだと一致するレコードはないですが、以下のようになると思います。
|
2
|
-
|
4
|
+
(女性の血液型をB型にすれば1件ヒットします。)
|
3
5
|
|
4
6
|
```SQL
|
5
7
|
select
|
@@ -7,11 +9,13 @@
|
|
7
9
|
from
|
8
10
|
asobi_a,asobi_b
|
9
11
|
where
|
10
|
-
(
|
12
|
+
(asobi_b.bl = 'a' and asobi_a.sex = '0'
|
13
|
+
and asobi_a.age = (select round(avg(age)) from asobi_a where asobi_a.sex = '0')
|
14
|
+
or
|
11
|
-
|
15
|
+
asobi_b.bl = 'o' and asobi_a.sex = '1'
|
16
|
+
and asobi_a.age = (select round(avg(age)) from asobi_a where asobi_a.sex = '1'))
|
12
|
-
and
|
17
|
+
and asobi_a.name = asobi_b.name
|
13
|
-
and asobi_a.
|
18
|
+
and asobi_a.flag = 0 and asobi_a.jotai = '00'
|
14
|
-
and asobi_a.AGE = (select round(avg(AGE)) from asobi_a where asobi_a.sex = '0')
|
15
19
|
group by
|
16
|
-
sex
|
20
|
+
sex;
|
17
21
|
```
|