列出购买订单的客户>平均付费订单

时间:2013-04-22 19:08:35

标签: sql sql-server-2008

以下是我的疑问:

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

为什么这不起作用?

3 个答案:

答案 0 :(得分: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)

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

答案 1 :(得分:0)

你过度工作了。从子查询中取出having子句。

答案 2 :(得分:-1)

select c.cust_lname, c.cust_fname, o.amount
from CUSTOMER c, orders o
where o.amount >
(select AVG (amount) from orders );