常用sql

按不同情况修改表中的值:

@Query(nativeQuery = true, value = "update user u set u.money = (case when :count > u.money  then 0 else u.money  - :count end) where u.id in(:ids)")

void subGold(@Param("ids") List<Long> ids, @Param("count") Integer count);

将一个表中的值插入到另一个表:

update `order_course` o LEFT JOIN `ir_course` c on c.`id` =o.`course_id` SET o.`begin_time` =c.`begin_time` WHERE o.`begin_time` IS NULL

原文地址:https://www.cnblogs.com/tian666/p/7986839.html