Files
BMS/bms-back/sql/price/order_bill_pickup_date_alter.sql
T
2026-10-16 18:01:46 +08:00

24 lines
790 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.
-- prc_order_bill.pickup_date from TAB_ORDER.PICKUP_DATE
SET NAMES utf8mb4;
SET @col := (
SELECT COLUMN_NAME FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'prc_order_bill'
AND COLUMN_NAME = 'pickup_date'
LIMIT 1
);
SET @sql := IF(
@col IS NULL,
'ALTER TABLE prc_order_bill ADD COLUMN pickup_date datetime DEFAULT NULL COMMENT \'收货时间(TAB_ORDER.PICKUP_DATE)\' AFTER order_time, ADD KEY idx_order_bill_pickup_date (pickup_date)',
'SELECT 1'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
-- backfill from prc_order when order_id linked
UPDATE prc_order_bill b
INNER JOIN prc_order o ON o.order_id = b.order_id
SET b.pickup_date = o.pickup_date
WHERE b.pickup_date IS NULL
AND o.pickup_date IS NOT NULL;