Hi,
i need to select some fields from differents tables, then group them by
a specific field using Doctrine and PgSql.
With SQL, postgres require all fields used in select into 'group by'.
If i need to group by some fields, i use "select distinct on (field1,
field2)", how could i do that with Doctrine??
My code is next:
$q = Doctrine::getTable('MgpAsiento')
->createQuery('a')
->select('a.id, a.fecha_ingreso AS fecha, a.correlativo
AS correlativo, a.glosa AS glosa, f.nombre AS fifo, c.nombre AS nombre,
l.id, (c.campo_1||c.campo_2||c.campo_3||c.campo_4||c.campo_5||c.campo_6)
AS numero, c.id AS cid')
->addSelect('SUM(l.monto_debe) AS debe')
->addSelect('SUM(l.monto_haber) AS haber')
->leftJoin('a.MgpLineaAsiento l')
->leftJoin('a.MgpFifo f')
->leftJoin('l.MgpCuentaContable c')
->whereIn('l.mgp_cuenta_contable_id', $ids) // Array
with ids
->andWhere('a.estado = true')
->andWhere('a.fecha_ingreso >= ?', $fdesde)
->andWhere('a.fecha_ingreso <= ?', $fhasta)
->andWhere('l.estado = true')
->groupBy('l.mgp_cuenta_contable_id, l.mgp_asiento_id')
->orderBy('c.id ASC, a.correlativo ASC, a.fecha_ingreso
ASC');
return $q->execute();
How you can see, I need to group by l.mgp_cuenta_contable_id first, then
by l.mgp_asiento_id...
Thanks in advance
--
Rodrigo Ruiz Fuentes
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en