sql语句性能优化

xiaoxiao2021-02-28  27

任务:一张1千七百多万数据量的表a与另一张表b进行模糊匹配,并为a表添加一个字段。

处理问题思路与解决:

1,通过like语句完成匹配

select   a.only,a.uname,b.name,b.分类号  into 分类表 from a,b  where a.uname like '%'+b.name+'%' and b.name like '%学院'

注:插入一张表与更新一张表的效率比较???

2,通过sqlserver的全文搜索

select a.name from a where  Contains(name, N'学院');

问题的关键在于contains后面只能是是字符串,不能用a.name这一列来代替使用。

3.通过截取并更新

a:计算出a表name字段的长度分类

select distinct len(name) from a order by len(name) desc

b:根据字段的长度,从大到小截取(一定要是从大到小,否则重复)与b表比较

Update a set a.分类号 =b .分类号 from A  a   join B  b on SUBSTRING(a.uname,1,19)=b.name

and LEN(b.name)=19 and a.分类号 is null

 

转载请注明原文地址: https://www.6miu.com/read-2650194.html

最新回复(0)