且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将两列相乘并在新列中显示

更新时间:2023-12-01 10:57:40

只需将 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