使用MYSQL在列中重新组合行

时间:2018-04-20 05:42:48

标签: php mysql

我有一个mysql数据库寄存器表如下:

id_register |date       | id_team |id_athlete | id_presence
1           |2018-04-19 | 3       |14         |1
2           |2018-04-19 | 3       |15         |2
3           |2018-04-19 | 3       |16         |1
4           |2018-04-20 | 3       |14         |3
5           |2018-04-20 | 3       |15         |2
6           |2018-04-20 | 3       |16         |1
7           |2018-04-19 | 4       |4          |1
8           |2018-04-19 | 4       |5          |2
9           |2018-04-19 | 4       |6          |1
10          |2018-04-20 | 4       |4          |2
11          |2018-04-20 | 4       |5          |1
12          |2018-04-20 | 4       |6          |1

id_team,id_athlete,id_presence显然是链接到相应文本值的外键。

我想按如下方式为每个团队输出存在值(例如,对于团队ID = 3)

date       | athlete 14 |  athlete 15 | athlete 16
2018-04-19 |1           |2            |1
2018-04-20 |3           |2            |1

我可以或者应该重新考虑我的桌子吗?

0 个答案:

没有答案