How to write SQL query as named_scope?
Posted
by keruilin
on Stack Overflow
See other posts from Stack Overflow
or by keruilin
Published on 2010-05-01T11:10:52Z
Indexed on
2010/05/01
11:17 UTC
Read the original article
Hit count: 224
ruby-on-rails
|sql
How can I translate the following SQL query into a named_scope?
select users.*, sum(total_quantity * total_price) as points_spent
from orders
join users on users.id = orders.user_id
where pay_type = 'points'
group by user_id
order by points_spent desc
Thanks!
© Stack Overflow or respective owner