我有 2 张桌子。第一个表包含大量用户数据。第二个表包含一个班级列表,以及职位是否已被填补。
我需要显示类,以及用户 ID 和用户名。
我试过做“加入”——但名字似乎只是互相覆盖,所以我每行只有一个名字。
用户表:
+----------+---------+
| user_ID | name |
+----------+---------+
| 1 | Smith |
+----------+---------+
| 2 | Jones |
+----------+---------+
| 3 | Tim |
+----------+---------+
etc
班级表:
+-------------+--------+--------+--------+---+---------+
| class_date | Spot 1 | Spot 2 | Spot 3 | . | Spot 16 |
+-------------+--------+--------+--------+---+---------+
| 2012/1/1 | 1 | 4 | 8 | . | 5 |
+-------------+--------+--------+--------+---+---------+
| 2012/2/1 | 2 | NULL | 1 | . | 3 |
+-------------+--------+--------+--------+---+---------+
| 2012/3/1 | 3 | 7 | NULL | . | NULL |
+-------------+--------+--------+--------+---+---------+
我想要达到的目标:
+-------------+-------------+------------+--------------+---+------------+
| class_date | Spot 1 | Spot 2 | Spot 3 | . | Spot 16 |
+-------------+-------------+------------+--------------+---+------------+
| 2012/1/1 | 1 - Smith | 4 - Ben | 8 - Drew | . | 5 - Loz |
+-------------+-------------+------------+--------------+---+------------+
| 2012/2/1 | 2 - Jones | NULL | 1 - Smith | . | 3 - Tim |
+-------------+-------------+------------+--------------+---+------------+
| 2012/3/1 | 3 - Tim | 7 - Dan | NULL | . | NULL |
+-------------+-------------+------------+--------------+---+------------+
任何帮助将不胜感激