表1包含列(行为),如
date product comment
12.01.2014 1201/sm/pb yes
13.01.2014 1202/sa/pa no
14.01.2014 1215/ja/pc yes
表2包含列(行为),如
certificate name
1201 pencil
1202 pen
1215 parker
我想在表1中添加一列(名称)
date product comment name
12.01.2014 1201/sm/pb yes pencil
13.01.2014 1202/sa/pa no pen
14.01.2014 1215/ja/pc yes parker
请告诉我如何添加行应满足的列 condition(product.table1 = certificate.table2 ==> table1中的名称)
谢谢你
答案 0 :(得分:2)
您需要加入product
列前缀的表格。
select t1.date, t1.product, t1.comment, t2.name
from table_1 t1
joint table_2 t2 on left(t1.product, strpos(t1.product,'/') - 1) = t2.certificate;