我正在寻找一种方法来计算我团队中每个球员(或这里只有一个球员)的上场时间。简化的数据库表如下:
matchid action minute player
-------------------------------------
1 subbedin 30 Pele
2 starter Pele
2 subbedout 50 Pele
3 subbedin 70 Pele
3 red 80 Pele
4 starter Pele
我现在对其他统计数据的查询:
$query = mysql_query("SELECT *,
SUM(CASE WHEN action = 'starter' OR action = 'subbedin' THEN 1 ELSE 0 END) AS games,
SUM(CASE WHEN action = 'goal' OR action = 'pengoal' THEN 1 ELSE 0 END) AS goals,
SUM(CASE WHEN action = 'yellow' THEN 1 ELSE 0 END) AS yellows,
SUM(CASE WHEN action = 'red' THEN 1 ELSE 0 END) AS reds,
// MINS GOES HERE
FROM league2012
GROUP BY player");
对于每个 matchid,基本计算是
( 90 OR subbedout OR red ) - ( starter OR subbedin )
例如在比赛 2
subbedout (50) - starter (0) = 50
最后,表格应如下所示:
player minutes goals, cards, etc.
---------------------------------------
Pele 210 ...
在过去的一个小时里,我一直在阅读教程,似乎无法弄清楚如何去做。