select
sp2.sale_id,
sum(sp2.payment_amount) as sumpaid,
sik2.quantity_purchased,
sik2.item_kit_unit_price,
sik2.discount_percent,
min(sp2.payment_date) as payment_date
from
sales_payments sp2,
sales_item_kits sik2,
sales_item_kits_taxes sit2
where
sik2.sale_id=sp2.sale_id
and sit2.sale_id=sp2.sale_id
group by
sp2.sale_id
请帮助使用(OUTER / LEFT?)JOIN简化此查询,其中所有表都没有相同的行数量..提前感谢
答案 0 :(得分:0)
我不知道你为什么使用skt2表。
select
sp2.sale_id,
sum(sp2.payment_amount) as sumpaid,
sik2.quantity_purchased,
sik2.item_kit_unit_price,
sik2.discount_percent,
min(sp2.payment_date) as payment_date
from
sales_payments sp2 LEFT JOIN
sales_item_kits sik2 ON sik2.sale_id=sp2.sale_id LEFT JOIN
sales_item_kits_taxes sit2 ON sit2.sale_id=sp2.sale_id
group by
sp2.sale_id