On Jul 8, 12:47 pm, Eric <[email protected]> wrote:
> Below is an example of an Oracle query getting year & month from a
> DATE field, then sorting . In my Sqlite db I am storing my dates as
> yyyy_mm_dd values. Would the equivalent be: or is there a better
> way?
>
> DB[:tbl].select{ |o| o.created[0..6] }.order( :created ).all
This wouldn't work. o.created would create an SQL::Identifier, which
doesn't support the [] method.
> SELECT DISTINCT
> TO_CHAR ( created, 'YYYY-MM' ) AS month
> FROM
> tbl
> ORDER BY
> 1 ASC;
This should give you roughly the same SQL:
DB[:tbl].select{TO_CHAR(created, 'YYYY-MM').as(month)}.distinct.order
(1).all
Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---