php – 更新MySQL表的特定记录
发布时间:2020-05-25 09:27:28 所属栏目:PHP 来源:互联网
导读:我正在处理电话系统,必须与多个服务供应商合作.对于一个供应商,我有一个像这样的 MySQL表country_codes – ---------------------------------------------------------country_code | area_code | country-----------------------------------------
|
我正在处理电话系统,必须与多个服务供应商合作.对于一个供应商,我有一个像这样的 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列之前没有,但我添加了它,因为我需要它用于我的PHP应用程序.我设法更新了一些记录的国家/地区代码(使用我上一个问题的回答) 我想要实现的是用相应的国家代码替换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 --------------------------------------------------------- 我希望我能够很好地解释自己.知道我怎么能用PHP-MySQL做到这一点? (我不介意使用PHP代码以这种方式操作表) 试试这个查询 –UPDATE 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) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
