我搜索了各种问题,但没有找到答案。我有一个 MySQL 表“团队”:
+--+----+------+
|id|name|active|
+--+----+------+
|1 |bla |1 |
|2 |blu |0 |
|3 |croc|1 |
|4 |bold|1 |
|5 |foo |1 |
|6 |bar |0 |
+--+----+------+
和一个表“数据”:
+----+-------+----+
|team|project|time|
+----+-------+----+
|2 |some |1 |
|2 |some2 |5 |
|3 |one |16 |
|3 |one2 |100 |
|5 |more |2 |
|5 |more2 |60 |
+----+-------+----+
在 PHP 中,我正在查询这样的数据:
SELECT t.name, t.active, d.time
FROM teams t
RIGHT JOIN data d ON (t.id = d.team)
ORDER BY t.id
一切正常,我的结果如下所示:
+----+------+----+
|name|active|time|
+----+------+----+
|blu |0 |1 |
|blu |0 |5 |
|croc|1 |16 |
|croc|1 |100 |
|foo |1 |2 |
|foo |1 |60 |
+----+------+----+
...但我希望我的结果如下所示:
+----+------+---+---+
|name|active|t1 |t2 |
+----+------+---+---+
|blu |0 |1 |5 |
|croc|1 |16 |100|
|foo |1 |2 |60 |
+----+------+---+---+
所以......我怎么能达到这个?我希望我没有忽略一个已经提出的问题...... :(
非常感谢!
编辑:首先,谢谢大家,但我忘记了一些东西......也有可能例如one2不存在......