回答編集履歴
3
goal_timeを日時と勘違いした時の間違いが残っていた
test
CHANGED
@@ -84,54 +84,72 @@
|
|
84
84
|
|
85
85
|
SELECT
|
86
86
|
|
87
|
-
|
87
|
+
(
|
88
88
|
|
89
|
-
|
89
|
+
SELECT
|
90
90
|
|
91
|
-
|
91
|
+
COUNT(1) + 1
|
92
92
|
|
93
|
-
|
93
|
+
FROM
|
94
94
|
|
95
|
-
|
95
|
+
goals g
|
96
96
|
|
97
|
-
|
97
|
+
INNER JOIN pairings p
|
98
98
|
|
99
|
-
|
99
|
+
ON g.pairing_id = p.id
|
100
100
|
|
101
|
-
|
101
|
+
WHERE
|
102
102
|
|
103
|
-
|
103
|
+
goals.player_id = g.player_id
|
104
104
|
|
105
|
-
|
105
|
+
AND (
|
106
106
|
|
107
|
-
|
107
|
+
(
|
108
108
|
|
109
|
+
goals.goal_time > g.goal_time
|
110
|
+
|
111
|
+
AND pairings.kickoff = p.kickoff
|
112
|
+
|
113
|
+
) OR (
|
114
|
+
|
115
|
+
pairings.kickoff > p.kickoff
|
116
|
+
|
117
|
+
)
|
118
|
+
|
119
|
+
)
|
120
|
+
|
121
|
+
) AS 点数
|
122
|
+
|
123
|
+
, pairings.kickoff AS 試合日時
|
124
|
+
|
125
|
+
, countries.name AS 対戦相手
|
126
|
+
|
109
|
-
|
127
|
+
, goals.goal_time AS ゴールタイム
|
110
128
|
|
111
129
|
FROM
|
112
130
|
|
113
|
-
|
131
|
+
players
|
114
132
|
|
115
|
-
|
133
|
+
INNER JOIN goals
|
116
134
|
|
117
|
-
|
135
|
+
ON players.id = goals.player_id
|
118
136
|
|
119
|
-
|
137
|
+
INNER JOIN pairings
|
120
138
|
|
121
|
-
|
139
|
+
ON goals.pairing_id = pairings.id
|
122
140
|
|
123
|
-
|
141
|
+
INNER JOIN countries
|
124
142
|
|
125
|
-
|
143
|
+
ON pairings.enemy_country_id = countries.id
|
126
144
|
|
127
145
|
WHERE
|
128
146
|
|
129
|
-
|
147
|
+
players.id = 対象プレーヤーのID
|
130
148
|
|
131
|
-
ORDER BY
|
149
|
+
ORDER BY
|
132
150
|
|
133
|
-
|
151
|
+
pairings.kickoff
|
134
152
|
|
135
|
-
|
153
|
+
, goals.goal_time
|
136
154
|
|
137
155
|
```
|
2
goal_timeが日時時ではないための修正
test
CHANGED
@@ -58,7 +58,9 @@
|
|
58
58
|
|
59
59
|
ORDER BY
|
60
60
|
|
61
|
+
tmp.kickoff
|
62
|
+
|
61
|
-
tmp.goal_time
|
63
|
+
, tmp.goal_time
|
62
64
|
|
63
65
|
```
|
64
66
|
|
@@ -128,6 +130,8 @@
|
|
128
130
|
|
129
131
|
ORDER BY
|
130
132
|
|
133
|
+
pairings.kickoff
|
134
|
+
|
131
|
-
goals.goal_time
|
135
|
+
, goals.goal_time
|
132
136
|
|
133
137
|
```
|
1
他のパターンの追記
test
CHANGED
@@ -67,3 +67,67 @@
|
|
67
67
|
デーブルの関係など詳細が分からないのでもろもろエスパーですが、こんな感じでしょうか。
|
68
68
|
|
69
69
|
Window関数を使用しているので、MySQL8.0からしか動きません。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
追記
|
74
|
+
|
75
|
+
上記の「点数」は「1試合内の何点目か」を出していました。
|
76
|
+
|
77
|
+
「該当選手の生涯で何点目か」であれば、下記のような感じです。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```sql
|
82
|
+
|
83
|
+
SELECT
|
84
|
+
|
85
|
+
(
|
86
|
+
|
87
|
+
SELECT
|
88
|
+
|
89
|
+
COUNT(1) + 1
|
90
|
+
|
91
|
+
FROM
|
92
|
+
|
93
|
+
goals g
|
94
|
+
|
95
|
+
WHERE
|
96
|
+
|
97
|
+
goals.player_id = g.player_id
|
98
|
+
|
99
|
+
AND goals.goal_time > g.goal_time
|
100
|
+
|
101
|
+
) AS 点数
|
102
|
+
|
103
|
+
, pairings.kickoff AS 試合日時
|
104
|
+
|
105
|
+
, countries.name AS 対戦相手
|
106
|
+
|
107
|
+
, goals.goal_time AS ゴールタイム
|
108
|
+
|
109
|
+
FROM
|
110
|
+
|
111
|
+
players
|
112
|
+
|
113
|
+
INNER JOIN goals
|
114
|
+
|
115
|
+
ON players.id = goals.player_id
|
116
|
+
|
117
|
+
INNER JOIN pairings
|
118
|
+
|
119
|
+
ON goals.pairing_id = pairings.id
|
120
|
+
|
121
|
+
INNER JOIN countries
|
122
|
+
|
123
|
+
ON pairings.enemy_country_id = countries.id
|
124
|
+
|
125
|
+
WHERE
|
126
|
+
|
127
|
+
players.id = 対象プレーヤーのID
|
128
|
+
|
129
|
+
ORDER BY
|
130
|
+
|
131
|
+
goals.goal_time
|
132
|
+
|
133
|
+
```
|