我正在尝试对我的一个查询使用嵌套聚合:
SELECT t.type, t.avgrent
FROM ( SELECT e.type, AVG(e.rental_rate) AS avgrent
FROM Equipment e
GROUP BY e.type) AS t
WHERE t.avgrent IN (SELECT MIN(t.avgrent) FROM t)
我一直收到以下错误:
数据库查询错误:表'database.t'不存在
谁能告诉我我做错了什么?
谢谢!
答案 0 :(得分:2)
你不能那样重用T
。这样的事情可能是:
SELECT t.type, t.avgrent
FROM ( SELECT e.type, AVG(e.rental_rate) AS avgrent
FROM Equipment e
GROUP BY e.type) AS t
WHERE
t.avgrent IN
(
SELECT
MIN(t2.avgrent)
FROM
(
SELECT
e.type,
AVG(e.rental_rate) AS avgrent
FROM Equipment e
GROUP BY e.type
) AS t2
)