回答編集履歴

3

修正3

2016/10/18 02:37

投稿

moonphase
moonphase

スコア6621

test CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
 
17
17
  ※以下修正しました11:30
18
+
19
+ もう一度修正しました11:36
18
20
 
19
21
  ```
20
22
 
@@ -34,9 +36,9 @@
34
36
 
35
37
  else '定年'
36
38
 
37
- end as '世代',
39
+ end as `世代`,
38
40
 
39
- count(*) as '人数'
41
+ count(*) as `人数`
40
42
 
41
43
  from (select year(curdate()) - year(birthday) - (right(curdate(),5) < right(birthday,5)) as age from emp3) t1 group by `世代`;
42
44
 

2

修正2

2016/10/18 02:37

投稿

moonphase
moonphase

スコア6621

test CHANGED
@@ -13,6 +13,8 @@
13
13
  見やすくしてみました。
14
14
 
15
15
 
16
+
17
+ ※以下修正しました11:30
16
18
 
17
19
  ```
18
20
 
@@ -36,6 +38,6 @@
36
38
 
37
39
  count(*) as '人数'
38
40
 
39
- from (select year(curdate()) - year(birthday) - (right(curdate(),5) < right(birthday,5)) as age from emp3) t1 group by '世代';
41
+ from (select year(curdate()) - year(birthday) - (right(curdate(),5) < right(birthday,5)) as age from emp3) t1 group by `世代`;
40
42
 
41
43
  ```

1

追記

2016/10/18 02:30

投稿

moonphase
moonphase

スコア6621

test CHANGED
@@ -5,3 +5,37 @@
5
5
  `year(curdate()) - year(birthday) - ( right(curdate(),5) < right(birthday,5) )`
6
6
 
7
7
  ではないですか?括弧が多い気がします。
8
+
9
+
10
+
11
+ 以下追記
12
+
13
+ 見やすくしてみました。
14
+
15
+
16
+
17
+ ```
18
+
19
+ select
20
+
21
+ case
22
+
23
+ when age between 10 and 19 then 10
24
+
25
+ when age between 20 and 29 then 20
26
+
27
+ when age between 30 and 39 then 30
28
+
29
+ when age between 40 and 49 then 40
30
+
31
+ when age between 50 and 59 then 50
32
+
33
+ else '定年'
34
+
35
+ end as '世代',
36
+
37
+ count(*) as '人数'
38
+
39
+ from (select year(curdate()) - year(birthday) - (right(curdate(),5) < right(birthday,5)) as age from emp3) t1 group by '世代';
40
+
41
+ ```