I have a query like this, I want to use this query in Codeigniter.
SELECT sum(price)
FROM (SELECT price
FROM items
ORDER BY price DESC
LIMIT 3
) AS subquery;
I have did
$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();
This gives output like this
SELECT sum(price), price
FROM items
ORDER BY price DESC
LIMIT 3;
What can I do to select the sum from the limited and ordered subquery?