gpt4 book ai didi

ruby-on-rails - 错误 : SELECT DISTINCT ON expressions must match initial ORDER BY expressions

转载 作者:数据小太阳 更新时间:2023-10-29 07:31:40 27 4
gpt4 key购买 nike

我的要求是得到不同的记录并按顺序

User.joins('INNER JOIN report_posts ON posts.id = report_posts.post_id').select('DISTINCT ON (report_posts.post_id) posts.id as report_posts.id as reported_id, report_posts.reported_at').order('report_posts.reported_at desc')

我知道这在 postgresql 中是不可能的,我已经读过这个 Postgresql DISTINCT ON with different ORDER BY

我想要它的解决方案,我该怎么做,它的替代方法?

最佳答案

您需要在订单中包含 DISTINCT 列:

.order('report_posts.post_id, report_posts.reported_at desc')

关于ruby-on-rails - 错误 : SELECT DISTINCT ON expressions must match initial ORDER BY expressions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com