CakePHP - Paginate / Query: find lowest of multiple fields & order by it
I am using CakePHP for a price-comparison website.
I have a table products with fields: id, pride_regular, price_action.
I would like t开发者_Python百科o combine the fields price_regular and price_action into a dynamic field: price. The lowest value of these two fields should be the value of the new price field. Also I want to order on it Ascending.
Should I use a custom MySQL-query?
This SQL query will get lowest values (except NULL values) over two columns:
SELECT LEAST(price_month_regular, ifnull(price_month_action, 9999)) AS least FROM cp_contracts
ORDER BY least
精彩评论