回答編集履歴
1
去年と今年を動的に変更するSQLを追記
test
CHANGED
@@ -37,3 +37,35 @@
|
|
37
37
|
前回の質問でわからなかった部分を、もう少し具体的に書くと、違った観点からアドバイスできるかも
|
38
38
|
|
39
39
|
しれません。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
> 去年と今年を実行日で判定するSQL
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```SQL
|
48
|
+
|
49
|
+
Select
|
50
|
+
|
51
|
+
shussekiNo,
|
52
|
+
|
53
|
+
name,
|
54
|
+
|
55
|
+
max(CASE WHEN tableb.year = YEAR(CURDATE()) - 1 then tableb.sintyo END) as lastYear,
|
56
|
+
|
57
|
+
max(case when tableb.year = YEAR(CURDATE()) then tableb.sintyo END) as currentYear
|
58
|
+
|
59
|
+
From
|
60
|
+
|
61
|
+
tablea
|
62
|
+
|
63
|
+
Left Outer Join tableb
|
64
|
+
|
65
|
+
on tablea.ID = tableb.id
|
66
|
+
|
67
|
+
Group by
|
68
|
+
|
69
|
+
tablea.shussekiNo
|
70
|
+
|
71
|
+
```
|