2017-08-19 119 views
0

我已經使用聯合查詢合併了三個表,併爲所有列創建了按功能分組。如何在SQL Server中將可空值更改爲非空值?

這裏是我的代碼:

select 
    Id, 
    Firstname, 
    Mark1, Mark2, Mark3            
from 
    (select 
     Id, Firstname, Null as Mark1, Null as Mark2, Null as Mark3 
    from 
     Parent  
    union                    
    select 
     Id, Null as Firstname, Mark1, Mark2, Null as Mark3 
    from 
     Child     
    union                    
    select 
     Id, Null as Firstname, Null as Mark1, Null as Mark2, Mark3 
    from 
     Mark) t 
where 
    Mark3 is not null                           
group by 
    Id, Firstname, Mark1, Mark2, Mark3 

在這裏,我已經設置mark3不是null使用WHERE條件,所以我的問題是如何改變空值不爲空的使用WHERE條件的字段的休息嗎?

回答

0

從您的查詢我建議使用加入,而不是(與空值工會) 那麼試試這個

Select parent.Id , parent. firstName, child.mark1,child.mark2,mark.mark3 
From parent 
inner join child on parent.id =child.id 
Inner join mark on mark.id=parent.id 
相關問題