Search code examples
sqloracle-databasecreate-table

SQL query, who visited in the past year


I am having problems with SQL querys. Specialy with this one, it goes like this.

I have 2 tables, patients and visits.

CREATE TABLE patients (
   ID_patients INTEGER NOT NULL,
   Name VARCHAR NOT NULL
);

and

CREATE TABLE visit(
    ID_visit INTEGER NOT NULL,
    DATE_visit DATE NOT NULL,
    FK_patients INTEGER NOT NULL
);

Now I would like to make a query, that would tell me which patients visited in the past year? And I don't mean in 2015 for instance but as in BETWEN(today-365 days) AND ( today - 730 days). I hope someone can give me some usefull tips.


Solution

  • select * from visit
    where DATE_visit between
    CURRENT_DATE - interval 2 year and CURRENT_DATE - interval 1 year;