1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| INSERT INTO `amount_sum` (`user_id`, `business_type`, `last_date`, `year_sum`, `month_sum`, `day_sum`, `pending_sum`) VALUES (#{userId}, #{businessType}, DATE(#{date}), 0, 0, 0, ABS(${amount})) ON DUPLICATE KEY UPDATE # 输入年小于等于(不变),输入年份大(0) `year_sum` = IF( YEAR(#{date}) <= YEAR(`last_date`), `year_sum`, 0 ), # 输入月小于等于(不变),输入月大(0) `month_sum` = IF( LAST_DAY(#{date}) <= LAST_DAY(`last_date`), `month_sum`, 0 ), # 输入日小于等于(不变),输入日大(0) `day_sum` = IF( DATE(#{date}) <= DATE(`last_date`), `day_sum`, 0 ), # + pending amount `pending_sum` = `pending_sum` + ${amount}, # last date 只能增加 `last_date` = IF( DATE(#{date}) < DATE(`last_date`), `last_date`, DATE(#{date}) );
|