Got the following query going.
SELECT
customer_id,
NTILE(5) OVER (ORDER BY MAX(oms_order_date)) AS r_score
FROM
mdwh.us_raw.l_dmw_order_report
WHERE
quantity_ordered > 0
AND customer_id IS NOT NULL
AND customer_id != ('')
AND UPPER(line_status) NOT IN ('','RETURN', 'CANCELLED')
AND UPPER(item_description_1) NOT IN ('','FREIGHT', 'RETURN LABEL FEE', 'VISIBLE STITCH')
AND (quantity_ordered * unit_price_amount) > 0
AND extended_amount < 1000 --NO BULK ORDERS
AND oms_order_date BETWEEN '2020-01-01' AND '2020-01-01'
AND SUBSTRING(upc,1,6) IN (SELECT item_code FROM item_master_zs WHERE new_division BETWEEN '11' AND '39')
GROUP BY
customer_id
ORDER BY
customer_id
All I'm doing here is, given some conditions, to give me the unique customer ID, then cluster their latest purchase date into quintiles and provide me with a score in the second column. But everytime I run the query, the r_score value keeps changing? What am I doing wrong..? Here's a snippet of what the table looks like (again, r_score value keeps changing):