回答編集履歴
2
追記
test
CHANGED
@@ -15,3 +15,21 @@
|
|
15
15
|
```
|
16
16
|
|
17
17
|
上記は相関副問合せでclassの人数を求めています。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
レベルを揃えるならクロス集計
|
22
|
+
|
23
|
+
```SQL
|
24
|
+
|
25
|
+
SELECT class
|
26
|
+
|
27
|
+
, sum(gender='男') as man_count, , sum(gender='女') as woman_count
|
28
|
+
|
29
|
+
, sum(gender='男') / count(*) as man_per, sum(gender='女') / count(*) as woman_per
|
30
|
+
|
31
|
+
FROM student
|
32
|
+
|
33
|
+
GROUP BY class
|
34
|
+
|
35
|
+
```
|
1
推敲
test
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
```SQL
|
6
6
|
|
7
|
+
SELECT class, gender, count(*) as count
|
8
|
+
|
7
|
-
|
9
|
+
, count(*) / (select count(*) from student where class=t1.class) as per
|
8
10
|
|
9
11
|
FROM student
|
10
12
|
|