我是codeigniter的初学者.
我有这样的查询,我想在codeigniter中使用此查询
SELECT sum(price)
FROM (SELECT price
FROM items
ORDER BY price DESC
LIMIT 3
) AS subquery;
我做了
$this->db->select('SUM(price)');
$this->db->select('price');
$this->db->from('items');
$this->db->order_by('price desc');
$this->db->limit(3);
$this->db->get();
这给出了这样的输出
SELECT sum(price), price
FROM items
ORDER BY price DESC
LIMIT 3;
我能做什么?
解决方法:
这样使用
$this->db->select_sum('price');
$this->db->select('price');
$this->db->from('items');
$this->db->order_by('price desc');
$this->db->limit(3);
$this->db->get();