2016-10-13 21 views
-1

我有一個select語句從哪裏獲得SQL - 通過ID字段

ProductID Gender Color Type  AgeRange 
344842  Boys NULL NULL  NULL  
344842  NULL Black NULL  NULL 
344842  NULL NULL Leggings NULL 
344842  NULL NULL NULL  2 to 4 Years 

我希望得到合併,這樣

ProductID Gender Color Type  AgeRange 
344842  Boys Black Leggings 2 to 4 Years 
+0

您是否可以直接從Table1選擇ProductID,Max(性別),max(顏色),max(類型),max(AgeRange),其中ProductID = 344842 group by ProductID – Veljko89

+0

您是否嘗試過任何操作? – Zack

回答

1
select 
productid, max(Gender) as Gender, 
max(Color) as Color, max(Type) as Type, max(AgeRange) as AgeRange 
from 
table 
group by 
productid 
1

行你可以嘗試這樣的

合併記錄
select productid, max(gender) as gender, max(color) as color, max(type) as Type, max(AgeRange) as AgeRange 
from yourtable group by ProductId 
1
select id,max(gender) gender, max(color) color, max(Type) Type, max(AgeRange) AgeRange from yourtable group by id