我想在 Rails/Active Record 中写这个查询
SELECT * FROM messages WHERE (realtor_id,created_at) IN ( SELECT realtor_id, MAX(created_at),message FROM messages WHERE `messages`.`user_id` = 8 GROUP BY realtor_id );
我尝试了一些语法,但它不起作用......我认为,解决方案很接近:
@discussions = Message.where(realtor_id: created_at: [Message.where(:user_id => current_user.id).select("realtor_id, MAX(created_at) as created_at").group("realtor_id").order("created_at ASC")])
有人可以帮助我吗?
感谢提前,
F。