select id, s
from (
select o_user_id as id, sum(total_price) as s
from Orders o
group by o.o_user_id
) as t1
where s = (select max(t1.s) from t1)
它返回一个错误,表示表 t1 不存在。
我想找出所有订单中消费最多的用户的id
最佳答案
该别名超出了子查询的范围
select id, s
from (
select o_user_id as id, sum(total_price) as s
from Orders o
group by o.o_user_id
) as t1
where s = (select max(t1.s) from t1)
你可以做到
WITH T1 AS
(
select o_user_id as id, sum(total_price) as s
from Orders o
group by o.o_user_id
)
SELECT id, s
FROM T1
WHERE s = (select max(t1.s) from t1);
关于mysql查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59219528/