My database is not really customers and orders, its customers and recipes for their eye tests (just in case someone wondered why I want my customers to order less often!)
I have a database for an optics chain, the recipe table has a branch ID, a patient ID, and the date they checked the eyes. Over time, patients will have more than one eye test indicated in the database. How can I get a list of patients who have had a prescription entered into the system more than once every six months. In other words, if the date of one prescription, for example, within three months from the date of the previous vacation for the same patient.
Sample data:
Branch Patient DateOfTest 1 1 2007-08-12 1 1 2008-08-30 1 1 2008-08-31 1 2 2006-04-15 1 2 2007-04-12
I do not need to know the actual dates in the result set, and this should not be exactly three months, but simply a list of patients whose prescription is too close to the previous prescription. In the given sample data, I want the request to be returned:
Branch Patient 1 1
Such a request will not be run very regularly, so I'm not too worried about efficiency. In our live database, I have a quarter of a million entries in the recipe table.
source share