根据现有字段更新列 [英] Updating column based on existing fields

查看:86
本文介绍了根据现有字段更新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新字段,我需要根据现有字段进行更新.想知道MYSQL是否可以使用变量执行此操作,还是必须使用PHP?由于该表非常庞大(超过30万行,我认为通过查询本身可以做到最好)

I created a new fields and I need to update it based on existing fields. Wondering if MYSQL can do this using variables or do I have to use PHP? Since the table is huge (300k+ rows, I assume its best done with a query itself is possible)

当前:

+-----+--------+--------------+
| pid |  mfr   |     pnum     |
+-----+--------+--------------+
|     | MCAFEE | HIDYFM-AA-DA |
+-----+--------+--------------+

预期:

+-----------------------+--------+--------------+
|          pid          |  mfr   |     pnum     |
+-----------------------+--------+--------------+
| MCAFEE___HIDYFM-AA-DA | MCAFEE | HIDYFM-AA-DA |
+-----------------------+--------+--------------+

推荐答案

只需连接两个字段并设置为pid

Just concatenate the two fields and set to pid

UPDATE table_name SET pid=CONCAT(mfr,"___",pnum)

这篇关于根据现有字段更新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆