2013-05-29 145 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 –

相關問題