kamaci
kamaci

Reputation: 75137

Aggregate Results According to Another Column

I have a SQL query:

SELECT COUNT(*), EXTRACT(year from DAY_DATE) FROM
( INNER_SELECT_QUERY )
GROUP BY DAY_DATE;

which returns results as like that:

4630    2013
7348    2014
9408    2013
5953    2013
7261    2015
5767    2013
9218    2013
14989   2013
11277   2013

How can I get result aggregated by distinct years? i.e.

22324   2015
34242   2014
23242   2013
54353   2012

I mean not repeated years, all related results to years are sum up?

Upvotes: 0

Views: 46

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

Put the extract() on in the group by:

SELECT COUNT(*), EXTRACT(year from DAY_DATE)
FROM ( INNER_SELECT_QUERY )
GROUP BY EXTRACT(year from DAY_DATE) ;

Upvotes: 4

Related Questions