diff --git a/db/views/sku_weight_discount.sql b/db/views/sku_weight_discount.sql index e836646df..2159e71f3 100644 --- a/db/views/sku_weight_discount.sql +++ b/db/views/sku_weight_discount.sql @@ -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 \ No newline at end of file +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 \ No newline at end of file