开发者

CakePHP - Paginate / Query: find lowest of multiple fields & order by it

开发者 https://www.devze.com 2022-12-25 12:30 出处:网络
I am using CakePHP for a price-comparison website. I have a table products with fields: id, pride_regular, price_action.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号