Update sku_weight_discount view for performance improvement

pull/8040/head
Qiuyi LI 2024-12-12 12:31:37 +01:00
parent 722908f2d4
commit 4043733136
1 changed files with 4 additions and 2 deletions

View File

@ -1,7 +1,9 @@
CREATE OR REPLACE VIEW sku_weight_discount_service_fees AS
SELECT s.id,
s.erp_code,
(SELECT sw.weight FROM sku_weight sw WHERE sw.sku_id = s.id ORDER BY effective_date DESC LIMIT 1) as weight,
sw.weight,
s.shipping_discount,
s.service_fee
FROM sku s
FROM sku_weight sw inner join (select sku_id, max(effective_date) max_date from sku_weight group by sku_id) sw2
on sw.sku_id = sw2.sku_id and sw.effective_date = sw2.max_date
join sku s on sw.sku_id = s.id