我有一个返回下表的查询:
Year IsFunded NotFunded 2003 Null 4 2003 3 Null 2004 Null 2 2004 8 Null
所以我需要:
SELECT Year, IsFunded, NotFunded FROM ( --myQuery that returns unflattened results )
我每年只需要一排。 像:
Year IsFunded NotFunded 2003 3 4 2004 8 2
答案 0 :(得分:4)
使用GROUP BY
和MAX
:
SELECT t.Year, MAX(t.IsFunded) AS IsFunded, MAX(t.NotFunded) AS NotFunded
FROM
(
--myQuery that returns unflattened results
) AS t
GROUP BY t.Year;