nix, shell, perl, php, mysql and mac os x tips and tricks

Saturday, October 6, 2018

Formula for pricing buy X get X (buy 1 get 1 free) promos

python code:
each_price = ( (current_price * quantity) - (current_price * (int(quantity / (buyX + getX) * getX) ) ) ) / quantity

Tuesday, July 24, 2018

MySQL insert or update a random value from a set of given values

UPDATE my_table SET my_field = (SELECT sub.code FROM (SELECT '01' AS code
UNION SELECT '02'
UNION SELECT '53'
UNION SELECT '54'
UNION SELECT '55'
UNION SELECT '56') as sub
ORDER BY RAND() LIMIT 1)