From c17f872962dc081eeb461dda242cc73f122bb0c5 Mon Sep 17 00:00:00 2001 From: Rikard Bartholf Date: Mon, 2 Jan 2017 16:15:52 +0100 Subject: [PATCH] PW-598 Add listprice column --- migrations/000.025.sql | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 migrations/000.025.sql diff --git a/migrations/000.025.sql b/migrations/000.025.sql new file mode 100644 index 0000000..74ca9bd --- /dev/null +++ b/migrations/000.025.sql @@ -0,0 +1,31 @@ +ALTER TABLE "product-printproducts" + DROP COLUMN IF EXISTS listprice, + ADD listprice INT NOT NULL DEFAULT 0; + +UPDATE "product-printproducts" +SET listprice = ROUND(price) +FROM ( + SELECT + printid, + price * COALESCE(pricepremium, 1) * 100 + * CASE printproducts.groupid + WHEN 2 + THEN 0.2 -- 0.2m2 is the minimum paid size for canvas + ELSE 1 END AS price -- 1.0m2 is the same for wallpaper + FROM "product-printproducts" printproducts + JOIN "product-products" products ON printproducts.productid = products.productid + JOIN ( + SELECT + groupid, + MIN(price) AS price + FROM "product-printprices" + GROUP BY groupid + ) prices ON printproducts.groupid = prices.groupid + LEFT JOIN ( + SELECT + designerid, + 1 + (pricepremium / 100) AS pricepremium + FROM designers + ) designers ON products.designerid = designers.designerid + ) s +WHERE "product-printproducts".printid = s.printid;