Using above code, it gives result with order of author_year based on
author
names. I need to order the query ascendingly based on the year which
presents in author_year. and I wish to print the oldest data based on
the
year not ordered by author name. Kindly give me some suggestion on this
issue.
Refactor the DB to have those fields available separately. You have two
distinct pieces of data munged together in one field.
I shouldn’t edit or modify the data in database. The data has not
munged.
The default data field is created with two pieces. In general author
referencing, the data will be included with year and author name. Author
name and year are the two pieces in author_year column. Kindly tell me
if
functions available to sort SQL query output with second piece only as
sorting element.
On 25 October 2010 14:55, Ar Chron [email protected] wrote:
I shouldn’t edit or modify the data in database. The data has not munged.
The default data field is created with two pieces. In general author
referencing, the data will be included with year and author name. Author
name and year are the two pieces in author_year column. Kindly tell me if
functions available to sort SQL query output with second piece only as
sorting element.
If you really want to ignore what others have said the :order options
takes an sql fragment. SQL has some string manipulation functions so
you can probably come up with a way of extracting the year from that
column, but such a query wouldn’t be able to use any indexes to help
with the ordering so you might end up with something slow as well as
something yucky.
If you really want to ignore what others have said the :order options
takes an sql fragment. SQL has some string manipulation functions so
you can probably come up with a way of extracting the year from that
column, but such a query wouldn’t be able to use any indexes to help
with the ordering so you might end up with something slow as well as
something yucky.
I tried
def author_yr
“#{self.author_year.last(4)}”
end.
But it shows “Undefined local variable or method ‘author_yr’”
when i use author_yr in find by
“:order => [“author_year like = ?”, author_yr]”. Please suggest me some
idea
in ordering.
Palani Kannan. K,
Doctoral Researcher,
Microbiology Department,
German Collection Center for Microorganisms and Cell Cultures,
Helmholtz-HZI Infectious diseases Research Campus,
38124, Braunschweig,
Germany.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.