2013-05-29 94 views
1

我有三个表将在本演示所示:sql fiddle demo预期的结果没有得到

预计这些条件,导致

enter image description here

在这里,您可以在演示检查这个activity_idregion_id并获得unit_id作为MEASUREMENT_UNIT_ID

我试过到目前为止:

select t.entity_id, t.parent_id, t.length,gu.measurement_unit_id 
    from tree t 
    left join product_autoselect_units u 
    on t.parent_id = u.region_id 
    or t.parent_id = u.activity_id 
    or t.entity_id IN (ACtivity_id) 
    left join units gu 
    on u.id = gu.unit_id 
    WHERE t.entity_id IN (Region_id) 

查询显示演示越来越这种情况,并导致

enter image description here

所以在这里为activity_id = 5753和region_id = 10没有得到预期的结果。我想要空值作为结果...你可以在演示中检查。

帮助将不胜感激。

回答

0
i have tried you query on given link in your post 

try to put your id for time being like in below query and see the result 
select t.entity_id, t.parent_id, t.length,gu.measurement_unit_id 
    from tree t 
    left join product_autoselect_units u 
    on t.parent_id = u.region_id 
    or t.parent_id = u.activity_id 
    or t.entity_id IN (ACtivity_id) 
    left join units gu 
    on u.id = gu.unit_id 
where t.entity_id in (5742,5753) 
    ##WHERE t.entity_id IN (Region_id) 
+1

thankx for help ....但这里5742和5753都是活动ID ...你可以一次使用一个...... meas one activity_id和一个region_id –