2016-04-22 6 views
1

Ich versuche, eine linke äußere Verbindung zu einer Unterabfrage zu machen, ist das möglich?Left Outer Beitreten Unterabfrage

Kann ich etwas tun ?:

##this is this weeks targets 
select * from targets t 
inner join streams s on s.id = t.stream_id 
where t.week_no =WEEKOFYEAR(NOW()) 

left outer join 

(
###############This is records selected so far this week 
select p.brand_id, p.part_product_family, sum(r.best) from records r 
inner join products p on p.id = r.product_id 
left outer join streams s on s.body = p.brand_id and s.stream = p.part_product_family 
where WEEKOFYEAR(r.date_selected) =WEEKOFYEAR(NOW()) 
group by p.brand_id, p.part_product_family; 
) sq_2 

on s.stream = sq_2.part_product_family 

Antwort

0

Dies funktioniert:

##this is this weeks targets 
select * from targets t 
inner join streams s on s.id = t.stream_id 

left outer join 

(
###############This is records selected so far this week 
select p.brand_id, p.part_product_family, sum(r.best) from records r 
inner join products p on p.id = r.product_id 
left outer join streams s on s.body = p.brand_id and s.stream = p.part_product_family 
where WEEKOFYEAR(r.date_selected) =WEEKOFYEAR(NOW()) and YEAR(r.date_selected) = YEAR(now()) 
group by p.brand_id, p.part_product_family 
) sq_2 

on s.body = sq_2.brand_id and s.stream = sq_2.part_product_family