mysql - 使用内部联接从其他表中减去值
问题描述
我试图从另一个表中减去另一个值(对不起,满嘴)但是我开发的 SQL 不断抛出相同的错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM products INNER JOIN order_details ON products.ItemID = order_details.Item' at line 2
这是我的代码:
UPDATE products SET Quantity = (products.Quantity - order_details.Quantity)
FROM products
INNER JOIN order_details
ON products.ItemID = order_details.ItemID
WHERE order_details.OrderID = 95 AND products.ItemID = order_details.ItemID;
它只是某人购买物品时的代码,它应该通过他们购买的任何东西的数量来减少产品表中的数量。任何帮助表示赞赏。
解决方案
thejoin
是该子句update
not 的一部分:SET
UPDATE products INNER JOIN order_details
ON products.ItemID = order_details.ItemID
SET Quantity = (products.Quantity - order_details.Quantity)
WHERE order_details.OrderID = 95;
推荐阅读
- java - 如何使用另一个类的属性创建(getter)方法
- http-status-code-404 - 热创建 Artifactory 页面 404 定制?
- java - SIP 注册失败 - 超时 - 清单中包含的所有权限,但应用程序中未包含来自互联网权限的接收数据
- ios - 在 iPad 上使用全屏模式的 iOS 12 出现问题 - 网络钓鱼检测误报
- ibm-certificate-manager - 云证书管理器与 SSL 服务
- c# - 静态变量到线程 C#
- symfony - 如何在 Symfony 4 中生成唯一 ID?
- ibm-watson - IBM Watson Language Translation 是否有机会跳过单词?
- vue.js - 如何在 Vue CLI 3 中生成多个 CSS 文件?
- javascript - 串联消耗大量内存,如何优化?