date difference in postgresql
This query will return the times a student retook an exam after more than 12 months from the first take:

SELECT Name, COUNT(Name)
FROM student, retake
WHERE student.ID = retake.ID
AND RetakeDate::date - '12 months'::interval &gt;= Examdate::date
GROUP BY Name


It subtracts 12 months from RetakeDate and checks if the resulting date is greater or equal to Examdate.

This query works too:

SELECT Name, COUNT(Name)
FROM student, retake
WHERE student.ID = retake.ID
AND age(RetakeDate::date, Examdate::date) &gt;= '12 months'::interval
GROUP BY Name


The function age(timestamp, timestamp) is documented here: https://www.postgresql.org/docs/current/static/functions-datetime.html

ATTENTION

Be aware that those two queries can give different results for periods that are exactly 12 months. The following returns true:

select age('2000-12-31'::date, '2000-01-01'::date) = '12 months'::interval;

 ?column? 
----------
 t
(1 row)


while this query returns false:

select '2000-12-31'::date - '12 months'::interval = '2000-01-01'::date;

 ?column? 
----------
 f
(1 row)


In fact:

select '2000-12-31'::date - '12 months'::interval;
      ?column?       
---------------------
 1999-12-31 00:00:00
(1 row)


while:

select age('2000-12-31'::date, '2000-01-01'::date);
       age       
-----------------
 11 mons 30 days
(1 row)


It is your choice to choose age() over date - interval. To solve this, you can use &gt; against &gt;=.