简体   繁体   English

将一个表中的值与第二个表中字段的所有行相乘

[英]Multiply a Value from one table with all rows of a field on the second table

I have two tables.我有两张桌子。 I want to multiply a single factor value from the currency table with all the rows of the Price field from the Product table.我想将货币表中的单个因子值与产品表中价格字段的所有行相乘。

Select Product.ID, (Product.Price* (select factor from Currency)) as NewPrice,
       Product.weight, Product.description
from Product,
     Currency

It does not seem to work.它似乎不起作用。 Please suggest the correct statement.请提出正确的说法。

It should be something like this (except the currency id on which you join the tables):它应该是这样的(除了你加入表格的货币 ID):

Select P.ID
      ,P.Price*C.factor as NewPrice
      ,P.weight
      ,P.description
from Product P
INNER JOIN Currency C
    ON P.[currencyID] = C.[currencyID]

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

相关问题 如何从一个表中选择所有行,并根据另一表计算字段值 - How can I select all rows from one table, calculating a field value based on another table SQL一个表中的所有行与第二个表中的所有行相邻 - SQL All rows in one table next to all rows from second table 从一个表中选择所有行,并根据第三个表从第二个表中选择总和 - Select all rows from one table and the sum from the second table based on the third table 全部来自第二张桌子中的一张桌子 - All from one table in the second table 获取一个表中的所有行,使用where子句对第二个表中的列求和 - get all rows from one table, sum on column from a second table using a where clause 从表中选择一个字段具有相同值的行 - Selecting rows from a table that have the same value for one field 从一个表中选择所有行,只要该ID不代表第二个表中的null - Select all rows from one table as long as that id doesnt represent a null in a second table 如何从一个表中获取所有行,但过滤第二个表? - How can I grab all rows from one table, but filter the second table? MySQL从一个表中减去第二个表中的某些行的值 - MySQL subtracting value from one table by some rows from second table SQL 将一个表连接到第二个表中包含每组最大值的行的选择 - SQL Joining One Table to a Selection of Rows from Second Table that Contains a Max Value per Group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM