gpt4 book ai didi

mysql - 查找数据库条目相对于 Rails 3 中 mysql 数据库中字段的顺序或排名

转载 作者:行者123 更新时间:2023-11-29 14:18:56 25 4
gpt4 key购买 nike

我有一个表,将我的用户与他们所支付的款项及其值(value)联系起来。

我需要能够找到用户付款的排名。这就是说:

Find Users payment -> Order Payments by value descending -> Return row position of users payment.

或者:

User pays $10

There are three people who have paid more than $10

Return 4

最佳答案

我不确定是否有办法使用 Arel 接口(interface)来实现此目的,但您可以执行类似的操作(假设您的用户已加载到 @user 中)

idx = nil
Payment.order("value desc").each_with_index do |payment, index|
if payment.user_id == @user.id
idx = index
break
end
end

虽然您可以查询小于 @user 为获取号码支付的金额的所有付款记录,但它不会考虑支付相同金额的记录,因为您不知道哪一个是首先是支付相同费用的用户。

关于mysql - 查找数据库条目相对于 Rails 3 中 mysql 数据库中字段的顺序或排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12095391/

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