我有下表...请参见下文
table users:
-------------
| id | name |
-------------
| 1 | mike |
| 2 | john |
| 3 | bill |
-------------
table trans:
---------------
| uid | spent |
---------------
| 1 | 5.00 |
| 1 | 6.00 |
| 2 | 5.00 |
| 3 | 5.00 |
| 3 | 10.00 |
---------------
expected output:
----------------------------
| id | name | spent | spent |
----------------------------
| 1 | mike | 5.00 | 6.00 |
| 2 | john | 5.00 | null |
| 3 | bill | 5.00 | 10.00 |
----------------------------
我正在使用以下查询...
SELECT d.id, d.name, m.spent
FROM users d
INNER JOIN trans m
ON d.id = m.uid GROUP BY id;
但它并没有向我展示我想要什么,有人帮助......
我已经尝试了以下代码...看起来我在附近但还没有....
SELECT d.id, d.name, m.spent
IF (m.id=5.00, 'spent', '') AS spent,
IF (m.id=6.00, 'spent1', '') AS spent1
FROM users d
INNER JOIN trans m
ON d.id = m.uid GROUP BY id;
有点想法...