在另一列中总共存储了几个MySQL列? [英] Sum total of several MySQL columns stored in another column?

查看:41
本文介绍了在另一列中总共存储了几个MySQL列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySQL数据库中添加几列,并将其存储在另一列中:

I have several columns in a MySQL database that I would like to add and store in another column:

column1     column2     column3    subtotal
10          10          10         30

有没有办法做到这一点?

Is there a way to accomplish this?

推荐答案

如何?

UPDATE tableName SET subtotal = (column1 + column2 + column3)

更新1

如果您真的不需要表中的小计列,只需将查询用作

Update 1

If you really don't need subtotal column in table just use query as

SELECT *, (column1 + column2 + column3) as subtotal
FROM tableName

这篇关于在另一列中总共存储了几个MySQL列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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