我刚开始学习MySQL,对表别名感到很困惑。当我尝试运行此查询时,它告诉我查询无效:
select customer_number
from
(select customer_number, count(*) as num
from orders
group by customer_number) as tmp
where num = (select max(num) in tmp)
我知道有一种简单的方法可以做到这一点,我只是为什么我的代码无法工作而感到困惑,非常感谢!
答案 0 :(得分:0)
您可以使用LIMIT
修改此查询:
SELECT customer_number
FROM orders
GROUP BY customer_number
ORDER BY COUNT(*) DESC
LIMIT 1