如何为多列创建按功能分组?

时间:2017-08-19 10:23:16

标签: sql-server-2008 group-by union

如何为多列创建按功能分组?

我在这里使用此查询。通过使用Max聚合函数,我删除了所有空值并得到了结果。

select Id,
MAX(Firstname) Firstname,
MAX(Mark1) Mark1,
MAX(Mark2) Mark2,
MAX(Mark3) 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
group by Id

那么我的问题是,我能否为其余的字段名(firstname,mark1,mark2,mark3)创建group?

0 个答案:

没有答案