【发布时间】:2016-10-05 09:45:29
【问题描述】:
我的模型中有以下选择:
$this->db->select("*, product.id as id, product.price as price, attribute.price as att_price, CASE WHEN(attribute.price > 0) THEN attribute.price ELSE product.price END as newprice");
当我获取结果时,我可以回显$product->newprice,它运行良好。问题是我想按产品价格或属性价格(如果存在)来订购结果。我可以通过在order_by() 中使用类似的CASE 轻松使其工作。但是我想跳过它并在那里使用newprice。
当我尝试$this->db->order_by("newprice ASC") 时,我得到以下错误:
错误号:105
“where 子句”中的未知列“newprice”
我不明白为什么我不能在 order by 函数中使用newprice,但是当我获取结果时我有 newprice。
【问题讨论】:
标签: php codeigniter activerecord sql-order-by case