Hristo Ivanov
Hristo Ivanov

Reputation: 719

Zend-Framework2. Sql query

I need some help, I have to implement this sql query in zend2:

SET @i:=-1; SELECT COUNT(*) AS cnt, AVG(ch01) AS ch01avg  FROM (
     SELECT @i:=@i+1 AS rownum,FLOOR(@i/60) AS GGG,ch01 
     FROM binTable 
     WHERE SUBDATE(NOW(),INTERVAL 11 DAY)<= start_date_time
)AS t GROUP BY GGG;

Feel free to use any other sql query as long it fulfulls the purpose, which is: getting the average of ch01 of every 60 entries.

Im not a native english speaker, Im eastern european :D.

Upvotes: 1

Views: 71

Answers (1)

Hristo Ivanov
Hristo Ivanov

Reputation: 719

Hi there i maneged to find a solution which works for me:

Having an instance of

Zend\Db\TableGateway\TableGateway

object which represents the table from which i want to make the query I did this:

$this->binTable is the Zend\Db\TableGateway\TableGateway object:

$result = $this->binTable->getAdapter()->query(" HERE GOES THE SQL QUERY ")->execute();

     use Zend\Db\ResultSet\ResultSet;

$resultSet = new ResultSet;
$resultSet->initialize($result);

Upvotes: 1

Related Questions