add point totalConsumed
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
ALTER TABLE `gao_point_account`
|
||||
ADD COLUMN `total_consumed` BIGINT NOT NULL DEFAULT 0 COMMENT '累计消耗积分' AFTER `total_earned`;
|
||||
|
||||
UPDATE `gao_point_account` account
|
||||
LEFT JOIN (
|
||||
SELECT `account_id`, SUM(-`point_delta`) AS `total_consumed`
|
||||
FROM `gao_point_ledger`
|
||||
WHERE `change_type` = 'CONSUME'
|
||||
AND `point_delta` < 0
|
||||
AND `deleted_at` IS NULL
|
||||
GROUP BY `account_id`
|
||||
) ledger ON ledger.`account_id` = account.`id`
|
||||
SET account.`total_consumed` = COALESCE(ledger.`total_consumed`, 0);
|
||||
Reference in New Issue
Block a user