Код: Выделить всё
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;
Подробнее здесь: https://stackoverflow.com/questions/294 ... ry-builder
Мобильная версия