I'm currently beginning a project for which i need to do some data management in SQL.
I want to check wether i have enough history for an individual to be included in the analysis I extracted data in a table that contains a column 'index_date' (date datatype) that correspond to the index date and multiple columns 'info_AAAA' that I use to state whether the individual figures on the database the year AAAA
i want to select only patients that figures in the database at least for the year AAAA, AAAA-1 and AAAA-2
But as I'm an absolute beginner in sql i can't figure how to do this
That's kind of self-descriptive, but - what is "index date"? What does it represent? Is it relevant for this case?
Now that sounds scary! Are you saying that table actually looks like this?
If so, you're doing it wrong. Table should have only one
presence_yearcolumn, e.g.because - what will you do next year? Add yet another column and modify ALL queries you wrote so far in order to include newly added column? And then repeat it the next year, and the year after, and ...? That's insane, don't do that.
Anyway: 3 years back can be calculated; question is what you really have in that table.
If it were my table, you'd e.g.
If you want to relate it to
index_date(presuming that it is aDATEdatatype column), you'dOther options are also possible; again, depending on what you really have.