gpt4 book ai didi

php - mysql 内连接和动态排名计算错误#1241

转载 作者:行者123 更新时间:2023-11-29 08:12:43 25 4
gpt4 key购买 nike

我正在尝试计算用户在我的门户中的排名...我将用户名从 user_table_name 连接到 rank_table 并动态计算排名,如果我单独运行查询,它运行良好,但是当我一起使用它时,出现 #1241 错误这是我的代码

SELECT (SELECT utn.name, rt.amount_left, rt.loan_amount, rt.currency_amount,
rt.stock_amount, rt.fd_amount, rt.user_money
FROM `user_table_name` AS utn INNER JOIN
`rank_table` AS rt on rt.user_id=utn.userid
) AS ut,
(SELECT COUNT(*)
FROM rank_table ui
WHERE (ui.amount_left) >= (uo.amount_left)
) AS rank
FROM rank_table uo
WHERE 1
ORDER BY rank ASC

感谢戈登的以下查询

SELECT utn.name, rt.amount_left, rt.loan_amount, rt.currency_amount,
rt.stock_amount, rt.fd_amount, rt.user_money,
(SELECT COUNT(*)
FROM rank_table ui
WHERE (ui.amount_left) >= (rt.amount_left)
) AS rank
FROM `user_table_name` utn INNER JOIN
`rank_table` rt
on rt.user_id = utn.userid
ORDER BY rank ASC;

但是查询给了我奇怪的结果,例如如果 10 和 11 位置的用户有相同的点,那么排名显示为 11 而不是 10..所以你能帮忙

最佳答案

select 的子查询只能返回一列。不是一群。我想你想要这样的东西:

SELECT utn.name, rt.amount_left, rt.loan_amount, rt.currency_amount,
rt.stock_amount, rt.fd_amount, rt.user_money,
(SELECT COUNT(*)
FROM rank_table ui
WHERE (ui.amount_left) >= (rt.amount_left)
) AS rank
FROM `user_table_name` utn INNER JOIN
`rank_table` rt
on rt.user_id = utn.userid
ORDER BY rank ASC;

关于php - mysql 内连接和动态排名计算错误#1241,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21268015/

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