【问题标题】:Multiplicate two fields from different columns - SQL将来自不同列的两个字段相乘 - SQL
【发布时间】:2016-04-20 01:26:58
【问题描述】:

我有以下两张表:

..................................

产品 |游戏 |数量

1------------2------------3

1------------3------------3

..................................

游戏ID |价格

2----------5

3-------------8

.......................

如何在 MS Access 中使用 WHERE 或类似的东西(例如,我想获得产品 1 的总成本)将每个游戏的数量 * 价格相乘? Game 是作为主键的 GameID 的外键。 我知道它与 JOINS 相关,但我无法使其工作。

感谢和问候

【问题讨论】:

  • 您在寻找 MS Access 或 SQL 的解决方案吗?

标签: sql ms-access


【解决方案1】:

您需要在下表之间执行JOIN。见Documentation For more information

select p.Product,
p.Game,
p.Quantity * q.Price as calculated_column
from Producttab p
inner join gametab q on p.Game = q.GameID
where p.Product = 3;

看起来它在抱怨那些表格别名。这是 MS-Access 版本:

select Producttab.Product,
Producttab.Game,
Producttab.Quantity * gametab.Price as calculated_column
from Producttab
inner join gametab on Producttab.Game = gametab.GameID
where Producttab.Product = 3;

【讨论】:

  • 我怎样才能按我想要的产品进行过滤?我的意思是,这将适用于所有产品,而不是我只需要的产品
  • @Wrong,包括WHERE 条件。请参阅答案中的编辑。
  • @Wrong,请再次查看答案中的编辑。做一些阅读和研究,并在途中学习。
  • 如何将其扩展为 3 个表?我是说。我有表 A、B 和 C。A 与 B 相关,B 与 C 相关。我想将 A 与 C 相关联
猜你喜欢
  • 2015-11-05
  • 1970-01-01
  • 2022-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-22
  • 2023-04-11
  • 1970-01-01
相关资源
最近更新 更多