简体   繁体   English

乘以主键链接的不同表中的值

[英]Multiplying values from different tables linked by primary keys

桌子的形象

I'd like to multiply values from two different tables( transactions.quantity*prices.price ) which are connected by primary keys. 我想乘以通过主键连接的两个不同表( transaction.quantity * prices.price )中的值。 I was trying to do it like this: select transactions.idd * prices.price join on discs transactions.idd = discs.idd join on prices discs.idp = prices.idp 我正在尝试这样做:选择transactions.idd * prices.price加入光盘transactions.idd = discs.idd加入价格discs.idp = prices.idp

Unfortunetely my knowledge from mysql is pretty bad and its obviously not working. 不幸的是,我对mysql的了解很差,而且显然不起作用。

Can somebody help me to fix this query? 有人可以帮我解决此查询吗?

You just have to join the tables before doing the multiplications. 你只需要加入做乘法之前的表。

SELECT A.quantity, C.price, A.quantity*C.price cost
FROM transactions A JOIN disc B
ON A.idd=B.idd  JOIN prices C
ON B.idp=C.idp;

You did not include the disc table in your join, and the syntax of your query is wrong. 您没有在联接中包含光盘表,并且查询的语法错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM