gpt4 book ai didi

mysql排序和使用子查询之间

转载 作者:行者123 更新时间:2023-11-29 00:58:59 25 4
gpt4 key购买 nike

我正在执行一个使用连接的查询。因为我使用了一个总金额的子查询。我想按如下子查询的结果排序。

"select users.*, (select sum(amount) as camount from donation where donation.uid=users.id) as camount from users where users.confirmed=1  and camount between 3 and 5 order by camount";

我得到一个错误:1064。

如何使用子查询的结果进行排序查询?

最佳答案

我不知道是什么触发了您遇到的错误,但是将子选择移动到内部联接应该会产生相同的结果。

SQL语句

select  users.*
, donation.camount
from users
INNER JOIN (
select uid
, sum( amount ) as camount
from donation
group by
uid
) donation ON donation.uid = users.id
where users.confirmed = 1
and donation.camount between 3 and 5
order by
donation.camount

关于mysql排序和使用子查询之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4647730/

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