Wednesday, April 06, 2005

Group By Substr in Derby

Derby doesn't let you do
select substr(some_column,1,10),count(*)
from some_table
group by substr(some_column,1,10)
But you can get the same result by doing
select short_version,count(*) from
(
select substr(some_column,1,10) as short_version
from some some_table
) a
group by short_version
Sam thought of this. The "a" is there as an alias name for the subselect. You don't have to use it, but if you don't put it in there, Derby rejects the SQL.

No comments: