Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sql = <<-SQL
- SELECT SUM(price) as total_price,
- SUM(distance) as total_distance,
- TO_CHAR(date, 'YYYY-MM') as month
- FROM Rides
- WHERE user_id = #{current_user.id}
- GROUP_BY month
- SQL
- Ride.find_by_sql(sql).each do |row|
- "#{row.month}: { total_distance: #{row.total_distance}, total_price: #{row.total_price} }"
- end
- ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "GROUP_BY"
- LINE 6: GROUP_BY month
- ^
- : SELECT SUM(price) as total_price,
- SUM(distance) as total_distance,
- TO_CHAR(date, 'YYYY-MM') as month
- FROM Rides
- WHERE user_id = 1
- GROUP_BY month
- str = "select sum(distance) as total_distance, sum(price) as total_price, to_char(date, 'YYYY-MM') as month from rides where user_id = #{ current_user.id } group by month"
Add Comment
Please, Sign In to add comment