Sample SQL QUERY to fetch Custom Price levels from a customer record

Use this query to fetch the custom price levels from a customer record:

QUERY:

SELECT
  internalid,
  customername,
  customeremail, 
  itemID,
  displayname,
  currency,
  unitprice, 
FROM (
    SELECT
      item.id AS internalid,
      c.altname AS customername,
      c.email AS customeremail,
      cip.price AS unitprice,
      BUILTIN.DF(cip.currency) AS currency,
      item.itemid AS itemID,
      item.displayname AS displayname,
      ROW_NUMBER() OVER (PARTITION BY cip.item ORDER BY ip.priceLevel ASC) AS rn
    FROM 
        customer AS c
    JOIN 
        customerItemPricing AS cip ON c.id = cip.customer
    LEFT JOIN 
        itemPrice AS ip ON cip.item = ip.item AND ip.priceLevel = 1
    JOIN
        item ON cip.item = item.id
    WHERE 
        cip.level = '-1'
        AND c.id = (?)
    ) t
WHERE 
    t.rn = 1

Leave a comment

Your email address will not be published. Required fields are marked *