怎么写一条sql语句,如果用户名username相同和商品编号goodsid相同,则把该商品的数量nums加一?
1个回答
展开全部
语句:
update table
set nums = 2
from
(
select goodsid,username from table
group by username
having count(goodsid) = 2
) a
where table.goodsid = a.goodsid
and table.username = a.username
update table
set nums = 2
from
(
select goodsid,username from table
group by username
having count(goodsid) = 2
) a
where table.goodsid = a.goodsid
and table.username = a.username
更多追问追答
追问
是多表查询吗,查一张表怎么做,我只查询cart表怎么做
追答
那就把table改成cart
update cart
set nums = 2
from
(
select goodsid,username from cart
group by username
having count(goodsid) = 2
) a
where table.goodsid = a.goodsid
and table.username = a.username
更新之前,先执行
select goodsid,username from cart
group by username
having count(goodsid) = 2
看看是否相同的都查询出来了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询