一些帮助小伙伴,我的表名为具有以下字段的产品
[Products]
pid
name
category
问题是该类别下有很多错误的条目引用了同一类别。
错误类别示例:
Bags and wallet
Bags and Wallets
Bag and Walles
Bags & Wallets
正确一个人应该是袋子&钱包
我想使用带有子查询的单个SQL语句来更改所有内容
UPDATE products
SET category = 'BAGS & WALLETS'
FROM products
WHERE category = (select category from products WHERE category like 'BAGS AND WALL')
答案 0 :(得分:0)
您可以实施MySQL的REGEXP
搜索:
UPDATE products
SET category = 'BAGS & WALLETS'
FROM products
WHERE category REGEXP 'BAGS? AND WALL'
答案 1 :(得分:-1)
了解LIKE
子句如何使用通配符%
:
UPDATE products
SET category = 'BAGS & WALLETS'
WHERE UPPER(category) LIKE 'BAGS AND WALL%'