我有两张火鸟桌,T1 和 T2。
T1 columns: pid, ean, desc
A T1 record: 1234, '102030', 'the desc'
和
T2 columns: eid, many_eans, eandesc
A T2 record: 4321, '634232;**102030**;273728', 'the ean desc'
我可以用这个选择查询得到我的结果:
select T1.pid
, T1.ean
, T1.desc
, T2.eandesc
from table1 as T1
inner
join table2 as T2
on T1.ean like '%' || T2.many_eans || '%'
但是查询花费的时间太长,因此我想向 T1 添加一个列,例如计算依据,将 T2.eandesc 文本添加到 T1 表中,其中 T1.ean 类似于 %T2.many_eans%
添加列后,我将执行此查询以获取我的数据。
select pid, ean, desc, eandesc from T1
如何将 T2.eandesc 添加到 T1 ?
目前您的T2
表未规范化,您正在many_eans
列中存储 CSV 数据。我建议您进行重组T2
,以便ean
每个记录出现一个,例如
T2 columns: eid, ean, eandesc
4321, '634232', 'the ean desc'
4321, '102030', 'the ean desc'
4321, '273728', 'the ean desc'
然后,下面的简单连接就足以得到你的结果:
select
T1.pid
T1.ean
T1.desc
T2.eandesc
from table1 as T1
inner join table2 as T2
on T1.ean = T2.ean
请注意,如果给定ean
在当前字符串之一中可能出现多次,则可以select distinct
改用它来确保您不会从T1
结果集中获得重复的结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句