以下是我的查询:
select c.cust_lname, c.cust_fname, o.amount
from CUSTOMER c, orders o
where o.amount >
(select AVG (o.amount)
from orders o
group by order_num
having o.amount > AVG(o.amount));
为什么这不起作用?
以下是我的查询:
select c.cust_lname, c.cust_fname, o.amount
from CUSTOMER c, orders o
where o.amount >
(select AVG (o.amount)
from orders o
group by order_num
having o.amount > AVG(o.amount));
为什么这不起作用?
您编写查询的方式如下所示:
select c.cust_lname, c.cust_fname, o.amount
from CUSTOMER c join
orders o
on c.customerId = o.customerId
where o.amount > (select AVG (o.amount)
from orders o)
请注意,您需要将两个表连接在一起才能获得所需的内容。
你过度设计了它。从您的子查询中取出 having 子句。
select c.cust_lname, c.cust_fname, o.amount
from CUSTOMER c, orders o
where o.amount >
(select AVG (amount) from orders );