我需要在from子句中使用select,但我会继续使用笛卡尔积。
select
customer.customer_name
,orders.order_date
,order_line.num_ordered
,order_line.quoted_price
,part.descript
,amt_billed
from (select order_line.num_ordered*part.price as amt_billed
from order_line
join part
on order_line.part_num = part.part_num
) billed
,customer
join orders
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;
不要太费力地看着其余部分。我已经知道,如果删除from
子句中的子选择和select子句中的amt_billed
,我就不会得到笛卡尔积。我做错了什么导致笛卡尔积?
答案 0 :(得分:1)
笛卡尔积的原因是,您没有加入带有orders
或Part
表的子选择。
首先,您不需要sub-select
SELECT customer.customer_name,
orders.order_date,
order_line.num_ordered,
order_line.quoted_price,
part.descript,
order_line.num_ordered * part.price AS amt_billed
FROM customer
JOIN orders
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;