postgresql---通过与 table 2 比较,在 table 1 中添加新列

postgresql--- add new column in table 1 by comparing with table 2

table 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

table 2 有像

这样的列(行为)
certificate  name
1201          pencil
1202          pen
1215          parker

我想在 table 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

有人请告诉我如何添加一列,其中的行应满足 条件(产品。table1 = 证书。table2 ==> table1 中的名称)

谢谢你

您需要在 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;