質問編集履歴
7
コードの編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,34 +1,110 @@
|
|
1
1
|
### 副問い合わせについて
|
2
2
|
```SQL
|
3
3
|
|
4
|
+
create table asobi_a(name varchar(50),flag int,jotai varchar(2),sex int,age int);
|
5
|
+
insert into asobi_a values("a",0,"00","0",21);
|
6
|
+
insert into asobi_a values("b",0,"00","1",18);
|
7
|
+
insert into asobi_a values("c",0,"00","1",15);
|
8
|
+
insert into asobi_a values("d",0,"00","0",21);
|
9
|
+
insert into asobi_a values("e",0,"00","1",42);
|
10
|
+
insert into asobi_a values("f",0,"00","0",34);
|
11
|
+
insert into asobi_a values("g",0,"00","0",76);
|
12
|
+
insert into asobi_a values("h",0,"00","0",18);
|
13
|
+
insert into asobi_a values("i",0,"00","1",20);
|
14
|
+
insert into asobi_a values("j",0,"00","1",35);
|
15
|
+
insert into asobi_a values("k",0,"00","1",16);
|
16
|
+
insert into asobi_a values("l",0,"00","0",26);
|
17
|
+
insert into asobi_a values("m",0,"00","0",53);
|
18
|
+
insert into asobi_a values("n",0,"00","0",21);
|
19
|
+
insert into asobi_a values("o",0,"00","1",32);
|
20
|
+
+------+------+-------+------+------+
|
21
|
+
| name | flag | jotai | sex | age |
|
22
|
+
+------+------+-------+------+------+
|
23
|
+
| a | 0 | 00 | 0 | 21 |
|
24
|
+
| b | 0 | 00 | 1 | 18 |
|
25
|
+
| c | 0 | 00 | 1 | 15 |
|
26
|
+
| d | 0 | 00 | 0 | 21 |
|
27
|
+
| e | 0 | 00 | 1 | 42 |
|
28
|
+
| f | 0 | 00 | 0 | 34 |
|
29
|
+
| g | 0 | 00 | 0 | 76 |
|
30
|
+
| h | 0 | 00 | 0 | 18 |
|
31
|
+
| i | 0 | 00 | 1 | 20 |
|
32
|
+
| j | 0 | 00 | 1 | 35 |
|
33
|
+
| k | 0 | 00 | 1 | 16 |
|
34
|
+
| l | 0 | 00 | 0 | 26 |
|
35
|
+
| m | 0 | 00 | 0 | 53 |
|
36
|
+
| n | 0 | 00 | 0 | 21 |
|
37
|
+
| o | 0 | 00 | 1 | 32 |
|
38
|
+
+------+------+-------+------+------+
|
39
|
+
create table asobi_b(bl char(2),name varchar(50));
|
40
|
+
insert into asobi_b values("a","a");
|
41
|
+
insert into asobi_b values("o","b");
|
42
|
+
insert into asobi_b values("ab","c");
|
43
|
+
insert into asobi_b values("a","d");
|
44
|
+
insert into asobi_b values("b","e");
|
45
|
+
insert into asobi_b values("b","f");
|
46
|
+
insert into asobi_b values("b","g");
|
47
|
+
insert into asobi_b values("o","h");
|
48
|
+
insert into asobi_b values("a","i");
|
49
|
+
insert into asobi_b values("a","j");
|
50
|
+
insert into asobi_b values("a","k");
|
51
|
+
insert into asobi_b values("o","l");
|
52
|
+
insert into asobi_b values("a","m");
|
53
|
+
insert into asobi_b values("b","n");
|
54
|
+
insert into asobi_b values("ab","o");
|
55
|
+
+------+------+
|
56
|
+
| bl | name |
|
57
|
+
+------+------+
|
58
|
+
| a | a |
|
59
|
+
| o | b |
|
60
|
+
| ab | c |
|
61
|
+
| a | d |
|
62
|
+
| b | e |
|
63
|
+
| b | f |
|
64
|
+
| b | g |
|
65
|
+
| o | h |
|
66
|
+
| a | i |
|
67
|
+
| a | j |
|
68
|
+
| a | k |
|
69
|
+
| o | l |
|
70
|
+
| a | m |
|
71
|
+
| b | n |
|
72
|
+
| ab | o |
|
73
|
+
+------+------+
|
4
74
|
|
5
|
-
|
6
75
|
select
|
7
76
|
sex,count(*)
|
8
77
|
from
|
9
78
|
asobi_a
|
10
79
|
where
|
11
|
-
|
80
|
+
age IN
|
12
81
|
(
|
13
82
|
select
|
14
|
-
|
83
|
+
sex,avg(AGE)
|
15
84
|
from
|
16
|
-
|
85
|
+
asobi_a,asobi_b
|
17
86
|
where
|
18
|
-
|
87
|
+
((asobi_b.bl = "a" and asobi_a.sex = "0")
|
19
|
-
|
88
|
+
or (asobi_b.bl = "o" and asobi_a.sex = "1"))
|
20
|
-
|
89
|
+
and asobi_b.bl in("a","o")
|
21
|
-
|
90
|
+
and (asobi_a.name = asobi_b.name
|
22
|
-
|
91
|
+
and asobi_a.FLAG = 0 and asobi_a.JOTAI = "00")
|
23
92
|
group by
|
24
|
-
|
93
|
+
sex
|
25
94
|
)
|
26
|
-
group by
|
95
|
+
group by
|
27
96
|
sex;
|
28
97
|
|
29
98
|
```
|
30
99
|
|
31
|
-
副問い合わせの中は大まかに言えば血液型がaかつ、男性か、血液型がoかつ、女性の人の平均年齢を性別ごとに求めています。
|
100
|
+
副問い合わせの中は大まかに言えば血液型がaかつ、男性か、血液型がoかつ、女性の人の平均年齢を性別ごとに求めています。
|
101
|
+
|
102
|
+
そして、副問い合わせが
|
103
|
+
(asobi_b.bl = "a" and asobi_a.sex = "0")の場合asobi_a.sex = "0"の平均年齢と一致する人を、(asobi_b.bl = "o" and asobi_a.sex = "1")の場合asobi_a.sex = "0"の平均年齢と一致する人を
|
104
|
+
出力したいのですが、今のSQL文だと、where句の中に、age in や sex = "0" などとりあえず入れてみたものの
|
105
|
+
ERROR 1241 (21000): Operand should contain 1 column(s)
|
106
|
+
と出てしまいます。
|
107
|
+
|
32
108
|
エラーが出る原因も何をすればエラーが出ないのかも分かりません。ぜひわかれば教えて頂きたいです。
|
33
109
|
|
34
110
|
|
6
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
### 副問い合わせについて
|
2
2
|
```SQL
|
3
|
+
|
4
|
+
|
5
|
+
|
3
6
|
select
|
4
7
|
sex,count(*)
|
5
8
|
from
|
5
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
### 副問い合わせについて
|
2
2
|
```SQL
|
3
|
-
コード
|
4
|
-
```
|
5
3
|
select
|
6
4
|
sex,count(*)
|
7
5
|
from
|
@@ -25,6 +23,7 @@
|
|
25
23
|
group by
|
26
24
|
sex;
|
27
25
|
|
26
|
+
```
|
28
27
|
|
29
28
|
副問い合わせの中は大まかに言えば血液型がaかつ、男性か、血液型がoかつ、女性の人の平均年齢を性別ごとに求めています。そして、副問い合わせが(asobi_b.bl = "a" and asobi_a.sex = "0")の場合asobi_a.sex = "0"の平均年齢と一致する人を、(asobi_b.bl = "o" and asobi_a.sex = "1")の場合asobi_a.sex = "0"の平均年齢と一致する人を出力したいのですが、今のSQL文だと、where句の中にage inと書いても、ERROR1241と出てしまいます。
|
30
29
|
エラーが出る原因も何をすればエラーが出ないのかも分かりません。ぜひわかれば教えて頂きたいです。
|
4
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
### 副問い合わせについて
|
2
|
+
```SQL
|
3
|
+
コード
|
4
|
+
```
|
2
5
|
select
|
3
6
|
sex,count(*)
|
4
7
|
from
|
@@ -28,9 +31,4 @@
|
|
28
31
|
|
29
32
|
|
30
33
|
|
31
|
-
バージョンは8.0です。
|
34
|
+
バージョンは8.0です。
|
32
|
-
|
33
|
-
|
34
|
-
```SQL
|
35
|
-
コード
|
36
|
-
```
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -31,6 +31,6 @@
|
|
31
31
|
バージョンは8.0です。
|
32
32
|
|
33
33
|
|
34
|
-
### 該当のソースコード
|
35
|
-
|
36
|
-
|
34
|
+
```SQL
|
35
|
+
コード
|
36
|
+
```
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,7 +23,8 @@
|
|
23
23
|
sex;
|
24
24
|
|
25
25
|
|
26
|
-
副問い合わせが(asobi_b.bl = "a" and asobi_a.sex = "0")の場合asobi_a.sex = "0"の平均年齢と一致する人を、(asobi_b.bl = "o" and asobi_a.sex = "1")の場合asobi_a.sex = "0"の平均年齢と一致する人を出力したい
|
26
|
+
副問い合わせの中は大まかに言えば血液型がaかつ、男性か、血液型がoかつ、女性の人の平均年齢を性別ごとに求めています。そして、副問い合わせが(asobi_b.bl = "a" and asobi_a.sex = "0")の場合asobi_a.sex = "0"の平均年齢と一致する人を、(asobi_b.bl = "o" and asobi_a.sex = "1")の場合asobi_a.sex = "0"の平均年齢と一致する人を出力したいのですが、今のSQL文だと、where句の中にage inと書いても、ERROR1241と出てしまいます。
|
27
|
+
エラーが出る原因も何をすればエラーが出ないのかも分かりません。ぜひわかれば教えて頂きたいです。
|
27
28
|
|
28
29
|
|
29
30
|
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,6 +26,10 @@
|
|
26
26
|
副問い合わせが(asobi_b.bl = "a" and asobi_a.sex = "0")の場合asobi_a.sex = "0"の平均年齢と一致する人を、(asobi_b.bl = "o" and asobi_a.sex = "1")の場合asobi_a.sex = "0"の平均年齢と一致する人を出力したいが、どうやって特定の条件で検索するかがわからないです。
|
27
27
|
|
28
28
|
|
29
|
+
|
30
|
+
バージョンは8.0です。
|
31
|
+
|
32
|
+
|
29
33
|
### 該当のソースコード
|
30
34
|
|
31
35
|
MySQL
|