gpt4 book ai didi

sql - SQLite:使用分组依据更新列

转载 作者:行者123 更新时间:2023-12-03 19:25:31 25 4
gpt4 key购买 nike

我正在使用SQLite,并试图弄清楚如何为已记录3次以上购买的客户提供折扣。我已经尝试了以下方法,但它仅通过退货来更新customer_ID组第一行的折扣。

update orders
set discount = price*0.5
where customer_ID = (
select customer_ID from orders
group by customer_ID
having count(customer_ID) > 3
);


如何实现上述预期结果?

最佳答案

您应该使用IN而不是=
=表示完全匹配等于
IN表示匹配列表中包含的所有结果

update orders
set discount = price*0.5
where customer_ID IN (
select customer_ID from orders
group by customer_ID
having count(customer_ID) > 3
);

关于sql - SQLite:使用分组依据更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44232672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com