新增一条数据的时候,添加if判断逻辑操作,具体sql如下:(MySQL数据库)
insert into t_coupon_record(account_id,coupon_id,coupon_name,valid_status)
select 1002,1,'新人优惠5元代金券',1 from DUAL
where not exists (
select account_id from t_coupon_record where account_id=1002
);
本文介绍了一种在MySQL数据库中插入数据时进行条件判断的方法,通过使用not exists子查询来避免为已存在的账户重复添加记录。
新增一条数据的时候,添加if判断逻辑操作,具体sql如下:(MySQL数据库)
insert into t_coupon_record(account_id,coupon_id,coupon_name,valid_status)
select 1002,1,'新人优惠5元代金券',1 from DUAL
where not exists (
select account_id from t_coupon_record where account_id=1002
);
1108

被折叠的 条评论
为什么被折叠?