Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- tmp."Internal Code", tmp."Seller SKU", tmp."EAN", tmp."Product Name",
- tmp."Product Desc", tmp."Brand Name", tmp."Vendor Price",
- tmp."Moneda", tmp."USA Quantity", tmp."MEX Quantity"
- FROM (
- SELECT
- row_number() OVER(PARTITION BY pt.default_code ORDER BY pt.default_code) row_num
- , pt.default_code AS "Internal Code"
- , pt.seller_sku AS "Seller SKU"
- , pt.etilize_ean AS "EAN"
- , pt.name AS "Product Name"
- , pt.description_sale AS "Product Desc"
- , pt.brand_name AS "Brand Name"
- , CASE
- WHEN l.vendor_support = True AND l.set_price = 'auto' THEN l.vendor_price
- ELSE l.product_price
- END AS "Vendor Price"
- , l.price_currency AS "Moneda"
- , CASE
- WHEN l.vendor_support = True AND (l.product_us_qty + l.vendor_quantity) > 4
- THEN (l.product_us_qty + l.vendor_quantity)
- WHEN l.vendor_support = False AND l.product_us_qty > 4
- THEN l.product_us_qty
- ELSE 0
- END AS "USA Quantity"
- , CASE WHEN l.product_mx_qty > 0
- THEN product_mx_qty
- ELSE 0
- END AS "MEX Quantity"
- FROM
- gpi_product_flatfile_line l
- INNER JOIN product_template pt
- ON l.product_tmpl_id = pt.id
- WHERE
- (pt.brand_name is not null and trim(pt.brand_name) != '') AND
- l.state = 'done'
- AND (l.product_mx_qty > 0 OR (l.product_us_qty + l.vendor_quantity) > 4)
- -- GROUP BY 1,2,3,4,5,6,7
- -- LIMIT 10
- ) tmp
- WHERE
- tmp."row_num" = 1
- AND tmp."Vendor Price" > 0
- AND (tmp."USA Quantity" > 4 OR tmp."MEX Quantity" > 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement