加入几个表以获得所需的结果

时间:2016-04-28 04:29:06

标签: oracle-sqldeveloper

需要加入多个表格,这些表格显示每个客户和由其下达的订单的total_value。报告客户编号和客户名称以及放置最高订单的客户的total_value。到目前为止,我有:

select customer.customer_num, customer.customer_name, price as total_value
from customer, orders, order_line, part 
where customer.customer_num = orders.customer_num
and orders.order_num = order_line.order_num
and order_line.part_num = part.part_num; 

这缩小了它,但现在我需要回答最初的问题,报告哪个客户在零件表中找到了最大的价格总和。

我无法弄清楚这种语法的位置?

customer.customer_num > sum(part.price) 

加入四个表后。

1 个答案:

答案 0 :(得分:0)

  select customer.customer_num, customer.customer_name, price as total_value
  from customer 
  join order on
 customer.customer_num = orders.customer_num
 join  order_line on
   orders.order_num = order_line.order_num
   join part on
  order_line.part_num = part.part_num  where customer.customer_num >sum(part.price);