0

如果我有如下表格:

Date    Name    Number    Period1    Period2    Period3  
-------------------------------------------------------
23-Oct  Barry   453       NULL       NULL       Room 4
23-Oct  Barry   453       NULL       Room 8     NULL
24-Oct  Barry   453       Room 2     NULL       NULL
23-Oct  Mary    139       Room 3     NULL       Room 4
23-Oct  Mary    139       NULL       Room 6     NULL
24-Oct  Mary    139       NULL       NULL       Room 9
24-Oct  Mary    139       Room 1     NULL       NULL

我怎样才能最好地查询它以获得下面的输出,即按日期、人员和期间分组?

Date    Name    Number    Period1    Period2    Period3  
-------------------------------------------------------
23-Oct  Barry   453       NULL       Room 8     Room 4
23-Oct  Mary    139       Room 3     Room 6     NULL
24-Oct  Barry   453       Room 2     NULL       NULL
24-Oct  Mary    139       Room 1     NULL       Room 9
4

1 回答 1

1
SELECT Date,
       Name,
       Number,
       MAX(Period1) AS Period1,
       MAX(Period2) AS Period2,
       MAX(Period3) AS Period3
FROM   T
GROUP  BY Date,
          Name,
          Number 
于 2013-10-04T12:26:40.333 回答