我擁有與另一個表(table2
- 包含客戶聯繫信息)相關的主表(table1
- 包含客戶主要信息),常用值爲ID
。通過SQL查詢找到複雜條件下的空值
在主表中的ID
值給我1列,另一個表可以給我更多的行,這取決於有多少接觸類型的客戶有,例如:
- main_phone(該行始終存在)
- HOME_PHONE
- work_phone
- 移動等
我試圖實現:
首先我想檢查移動值,如果行丟失或沒有移動值,但行存在,那麼我想檢查main_phone
值。
但是,如果有mobile
值,那麼我不想檢查main_phone
值。 如果main_phone
值也丟失,那麼我想要這些記錄。
目前,我有查詢:
Select customer
From table1 t1
Join table2 t2 on t1.id = t2.id
Where t2.type in (main_phone, mobile)
And t2.type_values in ('',null,'-')
但問題是,如果客戶有手機號碼和失蹤的電話號碼,這些客戶記錄也是在結果中顯示。
顯示正確的數據樣本和預期的結果 – scaisEdge
這裏是一個很好的開始。 http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/ –
您是否在尋找沒有手機或main_phone號碼的客戶? – Beth