Subqueries - Select * from subquery

Is it possible to run query:

$this->modelsManager->executequery('SELECT avg(a) FROM (SELECT sum(a) AS a, b, ,c FROM ...) AS sub')

?

Important part is SELECT FROM subquery. Beacuse I got exception:

Phalcon\Mvc\Model\Exception: Syntax error, unexpected token (, near to 'SELECT sum(a) AS a...

So is it possible to run such query with modelsManager?

I use Palcon 2.1.x



34.6k

Hello

You can try edit your sql the above to be like this:

$sql = "SELECT avg(a) FROM (SELECT sum(a) AS a, b, ,c FROM ...) AS sub";
$this->modelsManager->executequery($sql)