请帮助将 4 个 MySQL 查询合并为一个 [英] Please help merging 4 MySQL queries to One
本文介绍了请帮助将 4 个 MySQL 查询合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UPDATE RIA.Contact SET title = REPLACE(title, 'Cheif', 'Chief') where title rlike 'Cheif';
UPDATE RIA.Contact SET title = REPLACE(title, 'Manger', 'Manager') where title rlike 'Manger';
UPDATE RIA.Contact SET title = REPLACE(title, 'Manging', 'Managing') where title rlike 'Manging';
UPDATE RIA.Contact SET title = REPLACE(title, 'Excutive', 'Executive') where title rlike 'Excutive';
我们可以将上面的 4 个合并成这样的: UPDATE table SET A = IF(A > 0 AND A <1, 1, IF(A > 1 AND A < 2, 2,A)) 其中 A 不为 NULL;
Can we merge the above 4 to something like this : UPDATE table SET A = IF(A > 0 AND A < 1, 1, IF(A > 1 AND A < 2, 2, A)) WHERE A IS NOT NULL;
我知道我们可以使用过程来做到这一点,但是否可以只使用查询?
I know we can do this using a procedure but is it possible just using a query?
我试过了 -
UPDATE RIA.Contact SET title = IF(title rlike 'Cheif', replace(title,'Cheif','Chief'), IF(title rlike 'Manger', replace(title,'Manger','Manager'))) WHERE title rlike 'Cheif' or title rlike 'Manger';
不行!
推荐答案
UPDATE RIA.Contact
SET title = REPLACE(
REPLACE(
REPLACE(
REPLACE(title, 'Excutive', 'Executive'),
'Manging', 'Managing'),
'Manger', 'Manager'),
'Cheif', 'Chief')
WHERE title rlike 'Cheif'
OR title rlike 'Manger'
OR title rlike 'Manging'
OR title rlike 'Excutive';
这篇关于请帮助将 4 个 MySQL 查询合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文