我正在尝试从 1 个表中提取 2 组不同的数据。我不太确定如何解决这个问题。这是当前设置的表(相关)。
+----+-----------+----------+------+------------+--------+--------+
| id | recipient | given_by | time | expiration | points | reason |
+----+-----------+----------+------+------------+--------+--------+
| 1 | 72 | 1 | time | time | 2 | test |
| 3 | 15 | 4 | time | time | 5 | test |
+----+-----------+----------+------+------------+--------+--------+
+----+----------+
| id | username |
+----+----------+
| 1 | admin |
| 4 | user4 |
...
| 15 | user15 |
...
| 72 | user72 |
+----+----------+
通过使用以下查询,我能够让收件人与姓名相匹配:
SELECT
usr.username, usr.id, sl.recipient, sl.given_by,
sl.time, sl.experation, sl.points, sl.reason
FROM
DD_users AS usr
LEFT JOIN
DD_schittlist AS sl
ON (sl.recipient = usr.id)
GROUP BY
usr.id
ORDER BY
sl.points DESC,
usr.username
这将使收件人 72 与 user72 相匹配,但我也想让 given by 1 显示 admin 和 given_by 4 显示为 user4。