Simplify SQL Query which aggregates per year This query works, but uses TO_CHAR(date_created, 'YYYY') three times.

Is there a way to simplify this query?

SELECT TO_CHAR(date_created, 'YYYY'), count(*) 
FROM ticket 
WHERE date_created &gt;= '2013-01-01' and 
      date_created &lt;= '2017-06-01' 
GROUP BY TO_CHAR(date_created, 'YYYY') 
ORDER BY TO_CHAR(date_created, 'YYYY');


Result:

 to_char | count  
---------+--------
 2013    | 441500
 2014    | 574660
 2015    | 247910
 2016    | 601234


I want to simplify it. Performance does not matter at all (in this case). Unfortunately I found no matching tag for this question. I took "optimization".

I use PostgreSQL
A CTE can be used in this case:

WITH yourdata as (
    SELECT TO_CHAR(date_created, 'YYYY') AS tc_date_created
    FROM ticket
    WHERE date_created &gt;= '2013-01-01' AND 
          date_created &lt;= '2017-06-01' 
)
SELECT tc_date_created, count(*)
FROM yourdata 
GROUP BY tc_date_created
ORDER BY tc_date_created;