我正在处理电话系统,必须与多个服务供应商合作.对于一个供应商,我有一个像这样的
MySQL表country_codes –
--------------------------------------------------------- country_code | area_code | country --------------------------------------------------------- 93 | 93 | Afghanistan 0 | 9375 | Afghanistan Cellular-AT 0 | 9370 | Afghanistan Cellular-AWCC 355 | 355 | Albania 0 | 35568 | Albania Cellular-AMC 0 | 35567 | Albania Cellular-Eagle 213 | 213 | Algeria 0 | 21377 | Algeria Cellular-Djezzy 0 | 2135 | Algeria Cellular-Wataniya ---------------------------------------------------------
等等…
country_code列之前没有,但我添加了它,因为我需要它用于我的程序.我设法更新了一些记录的国家/地区代码(使用我上一个问题的回答)
我想要实现的是用相应的国家代码替换0.所以表格看起来应该是这样的 –
--------------------------------------------------------- country_code | area_code | country --------------------------------------------------------- 93 | 93 | Afghanistan 93 | 9375 | Afghanistan Cellular-AT 93 | 9370 | Afghanistan Cellular-AWCC 355 | 355 | Albania 355 | 35568 | Albania Cellular-AMC 355 | 35567 | Albania Cellular-Eagle 213 | 213 | Algeria 213 | 21377 | Algeria Cellular-Djezzy 213 | 2135 | Algeria Cellular-Wataniya ---------------------------------------------------------
试试这个查询 –
原文链接:https://www.f2er.com/php/240117.htmlUPDATE country_codes SET country_code := @c := IF(@c IS NOT NULL AND country_code = 0,@c,country_code) ORDER BY CAST(area_code AS CHAR)