回答編集履歴
1
修正
test
CHANGED
@@ -15,3 +15,61 @@
|
|
15
15
|
のようなやり方になります。あとはSQLの種類によって
|
16
16
|
|
17
17
|
じゃっかん書き方がかわってくると思います
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
# 修正します
|
22
|
+
|
23
|
+
構文が間違っていたようです、以下修正します
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```SQL
|
28
|
+
|
29
|
+
create table employees(user_id int unique,department_id int,salary int);
|
30
|
+
|
31
|
+
insert into employees values
|
32
|
+
|
33
|
+
(1001,10,250000),(1002,10,270000),(1003,10,280000),(2001,20,300000),(2002,20,220000),(3001,30,250000);
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
集計
|
42
|
+
|
43
|
+
```ここに言語を入力
|
44
|
+
|
45
|
+
select t1.department_id
|
46
|
+
|
47
|
+
,avg(salary) as avg
|
48
|
+
|
49
|
+
,sum(case when t1.salary>t2.avg then 1 else 0 end) avg_up
|
50
|
+
|
51
|
+
from employees as t1
|
52
|
+
|
53
|
+
inner join (select
|
54
|
+
|
55
|
+
department_id
|
56
|
+
|
57
|
+
,avg(salary) as avg
|
58
|
+
|
59
|
+
from
|
60
|
+
|
61
|
+
employees
|
62
|
+
|
63
|
+
group by
|
64
|
+
|
65
|
+
department_id
|
66
|
+
|
67
|
+
) as t2 on t1.department_id=t2.department_id
|
68
|
+
|
69
|
+
group by department_id
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|