我有两张table:
费用(每笔交易1行)
费用\元数据(每对键值对应一行+每行1列费用\ id)
我当前的代码为元数据中的每个键提供了一个新行
SELECT m.id, m.amount, s.key, s.value
FROM charges AS m
INNER JOIN charges_metadata AS s ON m.id = s.charge_id
WHERE key IN ('Product', 'Plan Type', 'Payment Plan')
我想看到的是:
+----------------+--------+---------+-----------+--------------+
| id | amount | Product | Plan Type | Payment Plan |
+----------------+--------+---------+-----------+--------------+
| 908asd7f098sa7 | 150 | T-shirt | Main | Monthly |
| 80as9d8f0as9d8 | 200 | Jeans | Regular | Yearly |
+----------------+--------+---------+-----------+--------------+
1条答案
按热度按时间nfeuvbwi1#
您需要使用键透视出值,这需要聚合: