我正在使用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
);
如何实现上述所需结果?
答案 0 :(得分:1)
您应该使用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
);