3

我有一个看起来像这样的表:

YEAR        RESOLUTION_DATE      CREATION_DATE  

2013                             2013/02/18
2012                             2012/05/26
2009                             2009/11/11
2013          2013/12/08         2013/12/01
2000                             2000/17/31
2007                             2007/12/08
2012                             2012/12/08
2012          2012/03/23         2012/03/10 
2012                             2012/12/08
2007                             2007/01/17
2012          2012/01/17         2012/01/10
2009                             2009/02/14  

我正在尝试进行查询,该查询将输出以下内容:

YEAR      COUNT_RESOLUTION_DATE      COUNT_CREATION_DATE  
2000               0                          1
2007               0                          2
2009               0                          2
2011               0                          0
2012               2                          5
2013               1                          2  

需要注意的是,我希望查询按 YEAR 计算 RESOLUTION_DATE 的数量,其中 RESOLUTION_DATE 不是 NULL,我想计算所有 CREATION_DATE 的数量。Oracle 数据库需要 SQL。

4

2 回答 2

4

试试这个:

SELECT 
COUNT(RESOLUTION_DATE) AS COUNT_RESOLUTION_DATE, 
COUNT(CREATION_DATE) AS COUNT_CREATION_DATE
FROM MyTable
GROUP BY YEAR
ORDER BY YEAR
于 2013-02-12T21:53:32.783 回答
3

如果您只想计算非 NULL 解决日期,这应该有效:

SELECT 
SUM(CASE WHEN RESOLUTION_DATE IS NULL THEN 0 ELSE 1 END) AS COUNT_RESOLUTION_DATE, 
COUNT(CREATION_DATE) AS COUNT_CREATION_DATE
FROM MyTable
GROUP BY YEAR
ORDER BY YEAR;
于 2013-02-13T14:03:04.027 回答