0

以下是我的查询:

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));

为什么这不起作用?

4

3 回答 3

2

您编写查询的方式如下所示:

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)

请注意,您需要将两个表连接在一起才能获得所需的内容。

于 2013-04-22T19:13:54.100 回答
0

你过度设计了它。从您的子查询中取出 having 子句。

于 2013-04-22T19:10:23.243 回答
-1
select c.cust_lname, c.cust_fname, o.amount
from CUSTOMER c, orders o
where o.amount >
(select AVG (amount) from orders );
于 2013-04-22T19:13:28.920 回答