我有一个具有标准列的表T1,如名称、电子邮件、phone_number。自定义字段作为键、值存储在custom_fields表中。
我需要在实际的表中将custom_fields的键名作为列名。我怎样才能做到这一点
表T1
id名称电子邮件
1约翰john@example.com
2山姆same@mydomain.com
custom_fields
id T1_id键值
1. 32岁
2 1职称首席执行官
3 2 40岁
42辆汽车拥有福特EcoSport
所需
T1_id名称电子邮件年龄job_title car_owned
1约翰john@example.com 32首席执行官未指定
2 Sam same@mydomain.com 40未指定福特EcoSport
发布于 2019-06-24 15:43:21
您应该使用表custom_fields,两次使用,一次用于工作,一次用于汽车
select t1.id, t1.name, t1.email, t2.value, t3.value
from t1
inner join custom_fields t2 on t1.id = t2.t1_id and t2.key = 'Job Title'
inner join custom_fields t3 on t1.id = t3.t1_id and t3.key = 'Car Owned' https://stackoverflow.com/questions/56739736
复制相似问题