首页 > 解决方案 > 将不同表中的两列相乘

问题描述

我有两张桌子

项目

Id    quantity  price
01     200        100
02     200        300

交易

Id Quantity 
01   1

但是当我乘以输出是

Total
100
300

我的查询是 select items.p*transaction.quantity as total from items,transaction

标签: mysqlsql

解决方案


这是你想要的吗?

select (t.quantity * i.price) as total
from transactions t join
     items i
     on t.id = i.id;

不过,这两个表会在id.


推荐阅读