order by sum()

228 views
Skip to first unread message

David

unread,
Jan 18, 2012, 12:52:42 PM1/18/12
to quer...@googlegroups.com
Hi,

I would like to construct this sentence

SELECT DISTINCT t0.ANIO, SUM(t0.TOTAL) FROM
        ESTADISTICAS_ACC_CIUDADANO t0 GROUP BY t0.ANIO ORDER BY
        SUM(t0.TOTAL) DESC

i do this:


QEstadisticasAccCiudadano qEstadisticasAccCiudadano = QEstadisticasAccCiudadano.estadisticasAccCiudadano;       
query.from(qEstadisticasAccCiudadano);   
query.groupBy(qEstadisticasAccCiudadano.id.anio);

but how can i order for the TOTAL column "SUM(t0.TOTAL)";
????

thanks in advance.



Timo Westkämper

unread,
Jan 18, 2012, 1:19:14 PM1/18/12
to quer...@googlegroups.com
Hi.

Did you try the following:

    query.orderBy(t0.total.sum().desc());

Cheers,
Timo
--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com



David Rocamora

unread,
Jan 19, 2012, 2:56:38 AM1/19/12
to quer...@googlegroups.com
I added 
 query.orderBy(t0.total.sum().desc());

But my problem is when i do this:

Query.list(t0.total.sum(), t0.id);

Therror that i got is:
the column t0.total.sum() is ambiguous and the query that it makes is:

SELECT DISTINCT t0.ANIO, SUM(t0.TOTAL) ,SUM(t0.TOTAL)
FROM 
        ESTADISTICAS_ACC_CIUDADANO t0 GROUP BY t0.ANIO ORDER BY 
        SUM(t0.TOTAL) DESC


It adds two time 
SUM(t0.TOTAL). 

Any idea about the reason???

Thanks. 
David Rocamora

Timo Westkämper

unread,
Jan 19, 2012, 3:09:09 AM1/19/12
to quer...@googlegroups.com
Hi.

Can you open a ticket for it on GitHub?

Br,
Timo
Reply all
Reply to author
Forward
0 new messages