本文介绍了将两列相乘并在新列中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个名为 customers
, cars
, carrent
的表.我想要的就是将 rentorder.days
与 cardetail.rentday
乘以并在 rentorder.totalrent
中显示该值.我无法实现这一目标.我怎样才能做到这一点.请提出任何建议.
I am having 3 tables named customers
,cars
,carrent
. All i want is to multiply rentorder.days
with cardetail.rentday
and show the value in rentorder.totalrent
. I am unable to achieve this. How can i do this.Any suggestions please.
SQL
SELECT customers.*,
cardetail.carname,
cardetail.model,
cardetail.company,
cardetail.color,
cardetail.rentday,
rentorder.days,
rentorder.totalrent
FROM rentorder
INNER JOIN customers
ON customers.custid = rentorder.custid
INNER JOIN cardetail
ON cardetail.id = rentorder.carid
推荐答案
只需将 rentday
与 days
相乘即可得到计算值 totalrent
选择
列表.
Just multiply rentday
with days
to get the computed value totalrent
in Select
list.
尝试一下
SELECT customers.*, -- Not sure this is allowed in [Mysql]
cardetail.carname,
cardetail.model,
cardetail.company,
cardetail.color,
cardetail.rentday,
rentorder.days,
cardetail.rentday * rentorder.days AS totalrent
FROM rentorder
INNER JOIN customers
ON customers.custid = rentorder.custid
INNER JOIN cardetail
ON cardetail.id = rentorder.carid
要保存数据,您需要使用内部联接
语法
To save the data you need to use update
from Inner Join
syntax
update rentorder
INNER JOIN customers
ON customers.custid = rentorder.custid
INNER JOIN cardetail
ON cardetail.id = rentorder.carid
SET
rentorder.totalrent = cardetail.rentday * rentorder.days
这篇关于将两列相乘并在新列中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!