You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by John Dunne <im...@alldunne.com> on 2006/03/31 18:13:55 UTC

sort by one column minus another column

Evening all,

I have a table with two columns; one that stores the start time of a
session and another with the stoptime of a session, cryptically named,
STARTTIME and STOPTIME.

Sorting by one or the other is easliy done by addDescendingOrderByColumn
(or, of course, addAscendingOrderByColumn). But how can I sort by the
difference between these two columns (i.e. the session duration)? This
can be done in sql by simply stating ORDER BY STOPTIME - STARTTIME, but
can I do this using the criteria object?

Thanks in advance,
John.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: sort by one column minus another column

Posted by Thomas Fischer <fi...@seitenbau.net>.
Most probably, the problem is one of the following:

- Torque tries to get a column name in the format TableName.ColumnName out
of the argument and does some heuristic guessing, which does not seem to
cover your case. Sadly, there is no central place where this is done, so it
is done differently in different places :-(. Changing this would need a
big-scale reworking of the internal logic of Torque's SQL generation.
However, you could try to improve  the guesswork for ther OrderBy-Columns
to guess correctly in your case.

- For some databases, the expression which is ordered by would need to be
added as a select column. Maybe this is missing.

Ah, now some hack comes to my mind which might work:

criteria.addAsColumn("myOrderBy", "(" + SomeTablePeer.COLUMN_B +" - " +
SomeTablePeer.COLUMN_A + ")");
criteria.addAscendingOrderByColumn("myOrderBy");

Maybe you have to leave out the brackets.

     Thomas

John Dunne <im...@alldunne.com> schrieb am 04.04.2006 16:54:05:

> I already tried your first suggestion, which failed. I just tried out
> your second suggestion but that's failed also. I may look at editing the
> code to see if I can get it to work, as I could do with this sorting
option!
>
> Thanks for your help Thomas,
>
> john.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: sort by one column minus another column

Posted by John Dunne <im...@alldunne.com>.
I already tried your first suggestion, which failed. I just tried out 
your second suggestion but that's failed also. I may look at editing the 
code to see if I can get it to work, as I could do with this sorting option!

Thanks for your help Thomas,

john.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: sort by one column minus another column

Posted by Thomas Fischer <fi...@seitenbau.net>.
I reckon you have tried the obvious way, but in the case you did not try it
here is the suggestion:

addAscendingOrderByColumn(SomePeer.STOPTIME + " - " + SomePeer.STARTTIME);

or, if this fails, maybe

addAscendingOrderByColumn("(" +SomePeer.STOPTIME + " - " +
SomePeer.STARTTIME+ ")");

works.

I did not try if this works with Torque 3.2. I am quite sure it will not
work with pre-3.2 Torque.

       Thomas

John Dunne <im...@alldunne.com> schrieb am 31.03.2006 18:13:55:

> Evening all,
>
> I have a table with two columns; one that stores the start time of a
> session and another with the stoptime of a session, cryptically named,
> STARTTIME and STOPTIME.
>
> Sorting by one or the other is easliy done by addDescendingOrderByColumn
> (or, of course, addAscendingOrderByColumn). But how can I sort by the
> difference between these two columns (i.e. the session duration)? This
> can be done in sql by simply stating ORDER BY STOPTIME - STARTTIME, but
> can I do this using the criteria object?
>
> Thanks in advance,
> John.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org