我有两张桌子-
Table1
命名为“老年城市”
A/S/A/B/A/A/B/B/ 21 /B/21
B
C
Table2
高级属性Attribute_value (英文)
/T1581-1997商业合同转嫁性、转嫁性、转轨性、无偿性
一种自愿性的商品
一种自愿性的自愿
一种较好的产品
B
B
现在我想创建表3,其中我获得了以下详细信息-
Table3
命名年龄城市电话护照定位技巧
注意- attribute_values应该在电话,护照,地点和技能标题下。在表3中,每个“名称”应该有一行。
假设Table2中的属性列中只有4个不同的值,对于找不到某个属性的名称,可以假定attribute_value为NULL。
发布于 2017-05-05 05:29:19
如果只有4属性,那么您可以使用如下所示。
注意:我假设这是您正在进行的测试场景。在实际数据库中,name对密钥不是一个好主意,因此您不能基于name进行处理。
select t1.*, t2.*
from
table1 t1
left join
( select name,
max(case when attribute = 'Phone'
then attribute_value end) as Phone ,
max(case when attribute = 'Passport'
then attribute_value end) as Passport,
max(case when attribute = 'Location'
then attribute_value end) as Location,
max(case when attribute = 'Skills'
then attribute_value end) as Skills
from table2
group by name
) t2
on t1.name=t2.name左联接只是返回不存在于null中的name的table2。如果您不想要这些,那么使用inner join。
https://stackoverflow.com/questions/43796772
复制相似问题