在线急等,求一个sql复合查询的语句

vgy12304 2009-07-30 03:58:19
购物商品表shopcart
------------------------
id 流水码
usid 会员id
ordid 订单编号
ptid 商品ID
nums 数量


商品表product
--------------------------
id 流水码
Amount 商品剩余数量

我想一句话实现,在商品表product中减去所有的购物表shopcart包含的商品的数量

update product set Amount=Amount-??? where id in (select ptid as id from shopcart)
...全文
89 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qizhicong2 2009-07-30
  • 打赏
  • 举报
回复
sql server 和 oracle 是不一样的,你的什么数据库?
  • 打赏
  • 举报
回复
update product set Amount = Amount-nums from product,shopcart where product.id=shopcart.ptid




UPDATE product SET Amount = Amount-nums FROM product LEFT JOIN shopcart ON product.id=shopcart.ptid
vgy12304 2009-07-30
  • 打赏
  • 举报
回复
access的,楼上两位的不好用,不过还是谢谢你们
cpp2017 2009-07-30
  • 打赏
  • 举报
回复
update A set Amount = Amount-nums

FROM product AS A
INNER JOIN shopcart as B

ON A.id = B.ID


郭大侠_ 2009-07-30
  • 打赏
  • 举报
回复
试试这句,我无法测试
update product set Amount=Amount-a.nums from shopcart a where id=a.ptid
郭大侠_ 2009-07-30
  • 打赏
  • 举报
回复
sql server 和 oracle 是不一样的,你的什么数据库?

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧