2015-12-21 26 views
-3

if語句事件表是返回null或空白的用戶ID,然後在查詢應該從領先組表導致.........沒有簡單的方法如何從兩個表

case lgid='' then select 
    select user_id from event where created_timestamp in (select user_id 
    from lead_group as lgid where created_timestamp in(select event_id 
    from lead where created_timestamp=1450473084)) 
ELSE 
    select user_id from event where created_timestamp in(select event_id 
    from lead where created_timestamp=1450473084) 
END 
+1

你能解釋一下你想從這些查詢做什麼??? – Abbas

回答

0

獲取記錄如果要從兩個表中檢索數據,請使用JOIN函數。 link

1

我假設:

events table contains event_id and user_id 
    lead_group table contains user_id 
    lead table contains event_id and created_timestamp 

查詢:

select e.user_id 
    from events e 
    join lead_group lg on lg.user_id = e.user_id 
    join lead l on l.event_id = e.event_id and l.created_timestamp =  '1450473084' 
+0

thanxs Naveed我已經使用UNION這個,這是一個正確的方法 –