MAX and MIN functions in Cakephp 3

Asked

Viewed 57 times

0

I am trying to perform a database search that returns the lowest and highest value of the 'time' (time) field using the following code in Cakephp 3:

$pedidos = TableRegistry::get('Pedidos');
$hora_max = $pedidos->find('list', array('fields' => array('MAX(hora)  AS 'hora_maxima')));
$hora_minima = $pedidos->find('list', array('fields' => array('MIN(hora)  AS 'hora_minima')));
debug($hora_maxima);

However it returns me the following error:

syntax error, Unexpected T_OBJECT_OPERATOR.

Could someone help me, please?

1 answer

3


Looking superficially and considering the error message,

syntax error, unexpected T_OBJECT_OPERATOR

There’s an extra quote:

'MAX(hora)  AS 'hora_maxima'

Correct by removing the middle quote:

'MAX(hora)  AS hora_maxima'

Example:

$hora_max = $pedidos->find('list', array('fields' => array('MAX(hora)  AS hora_maxima')));

Note that the same happens in MIN assembly():

'MIN(hora)  AS 'hora_minima'
               /\
              /  \
               ||
               ||
  • Daniel Omine thank you so much for your help. I am very happy to know that we have such a close community. I hope I can soon be contributing to the community as well. Again, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.