Files
shanxia2.0/backend/scripts/migrate_20260808_crm_contract_freight.sql
T
2026-08-08 20:43:48 +08:00

16 lines
485 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 合同主表增加运费字段,并从关联报价单回填历史数据(仅 freight=0 且有 quote_id)
ALTER TABLE `crm_contract`
ADD COLUMN `freight` decimal(18,2) NOT NULL DEFAULT 0.00 COMMENT '运费'
AFTER `amount_with_tax`;
UPDATE `crm_contract` c
INNER JOIN `crm_quote` q
ON q.id = c.quote_id
AND q.tenant_no = c.tenant_no
AND q.del_flag = 0
SET c.freight = IFNULL(q.freight, 0)
WHERE c.del_flag = 0
AND c.quote_id IS NOT NULL
AND IFNULL(c.freight, 0) = 0;