在两个表中做一些值的计算,并将其存储在第三个表mysql中 [英] Do some calulations of the values in two table and store it in third table mysql

查看:110
本文介绍了在两个表中做一些值的计算,并将其存储在第三个表mysql中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

table1

| email           | result  |
----------------------------
| abc@gmail.com   |0.12      |
| dsv@gmail.com   |0.23      |
| rthgmail.com    | 0.45     |
| hfg@gmail.com   |0.56      |
| yyt@gmail.com   | 0.78     |
| hjg@gmail.com   | 0.35     |

table2

 | resource        |
 -------------------
 | 0.5             |

table3

| temp            |
-------------------
|NULL             |

现在我想分别从table1和table2中为email abc@gmail.com添加结果和资源将结果保存在table3中。我想每次都更新table3。

Now I want addition of result and resource from table1 and table2 respectively for email abc@gmail.com and save the result in table3. I want to update the table3 every time.

我试过下面但是不工作:

I tried the following but its not working:

UPDATE table3 SET temp = table1.result + table2.resource WHERE email = 'abc@gmail.com'

$ b $

推荐答案

您可以使用子查询:

UPDATE Table3 t
SET t.temp = (SELECT s.result+p.resource
              FROM table1 s INNER JOIN table2 p
              ON(s.email = 'abc@gmail.com'))

如果您的Table3没有数据:

If your Table3 doesn't have data yet:

INSERT INTO Table3 
(SELECT s.result+p.resource
 FROM table1 s INNER JOIN table2 p
  ON(s.email = 'abc@gmail.com'))

这篇关于在两个表中做一些值的计算,并将其存储在第三个表mysql中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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