SQL 更新语句 [英] SQL Update Statement

查看:53
本文介绍了SQL 更新语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个表,Products 和 ShoppingCart,我想根据 ShoppingCart 中指定的产品名称和数量更新和减少 Products 表的产品数量".我该怎么做?

I have 2 tables, Products and ShoppingCart and I would like to update and decrease the product's 'Quantity' of the Products table based on the Product name and Quantity specified in the ShoppingCart. How can i do this?

表:产品字段:产品名称、产品数量

Table: Products Fields: ProductName, ProductQty

表:购物车字段:产品名称、产品数量

Table: Shopping Cart Fields: ProductName, ProductQty

访问数据库

推荐答案

您应该有一个产品 ID.但是:

You should have a product id. However:

 UPDATE Products p
 INNER JOIN [Shopping Cart] s
 ON p.[Product Name] = s.[Product Name]
 SET p.ProductQty = p.ProductQty - s.ProductQty

您也应该去掉字段名和表名中的空格.

You should get rid of spaces in field and table names, as well.

这篇关于SQL 更新语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆