Mysql 将两列相乘并以新列显示
我有三张桌子,分别是“顾客”、“汽车”和“卡伦特”。我只想将rentorder.days与cardetail.rentday相乘,并在rentorder.totalrent中显示值。我无法做到这一点。我怎样才能做到这一点。 有什么建议吗 SQL 只需将rentday与days相乘,即可获得选择列表中的计算值totalrent 试试这个Mysql 将两列相乘并以新列显示,mysql,sql,database,Mysql,Sql,Database,我有三张桌子,分别是“顾客”、“汽车”和“卡伦特”。我只想将rentorder.days与cardetail.rentday相乘,并在rentorder.totalrent中显示值。我无法做到这一点。我怎样才能做到这一点。 有什么建议吗 SQL 只需将rentday与days相乘,即可获得选择列表中的计算值totalrent 试试这个 SELECT customers.*, -- Not sure this is allowed in [Mysql] cardetail.carna
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
要保存数据,需要使用“从内部联接更新”语法
在rentorder.totalrent中显示值-您只是想显示它,还是将其保存在rentorder表中?@PaulSpiegel我想保存它的Select customers.*,-不确定[Mysql]中允许这样做,-是的@VR如果我想保存值怎么办?选择customers.*,-不确定[Mysql]中是否允许这样做,-是的!-只有第一个。SELECT col1,table.*不起作用。@endo64我刚刚测试了SELECT productIdata,categories.*-它在MariaDB上起作用。我也经常在MySQL上这样做来调试查询。@endo64,您使用的是*而不是表别名,如t1.*-这是不同的。使用SELECT col1,*-*将包括col1-这意味着您将选择col1两次。
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
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