We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

group by, count and sum in a model

Hello I was reviewing the documentation

https://docs.phalcon.io/en/latest/reference/models.html#generating-calculations

in a query I can get added value, sumed or averaged, or counted by a group, but the model must create an object for each sum or count. You can create an object that has a number average ,sums and count

I did not get that. Can u give us example where is the issue?

Can explain what's your problem ? Don't understand.



81.2k
edited Sep '16

I want to do this query with options Phalcon

 SELECT  case c.caja_formap when 'B' then 'BILLETE' when 'C' then 'MONEDAS' else 'OTROS' END AS TIPO,
caja_valor,
count(c.caja_cantidad) as cuantos,  
sum(c.caja_cantidad) as cantidad,   
round(sum(c.caja_total),2) as total,
upper(expresar_en_letras.numero_a_letras(c. caja_valor))as valorletras
FROM CAJA c
where to_char(c.caja_fecha,'dd/mm/yyyy')=to_char(sysdate,'dd/mm/yyyy')
group by c.caja_formap,c.caja_valor
ORDER BY c.caja_formap,c.caja_valor asc

Just use query builder ?