Gaywood and Grim... have done a powerful job of recruiting friends for their marathon runs, and there's now 1000 different people! We're tracking all their marathon runs in a database table that looks a bit like this:
Code:
Race_ID Runner Date_of_Marathon Time Sex
1 Grim... 20170601 240 M
2 Gaywood 20170910 226 M
3 Jem 20161210 210 F
4 Mimi 20170522 220 F
Now I've got soooo much data, I want to know what the old data is so I can like get rid of it or something, save those precious bytes. But I'm powerful sexist. So what I'm looking for is a select query that will give me the races that are more than 3 months old if the runner is a dude, or more than 6 months old if the runner is a chick. And I want 10 results (if there are 10 results).
So something like this (pseudocode)
Code:
select top 10 race_id from races where (datediff(mm,getdate(),date_of_marathon)>6 if sex='m') or (datediff(mm,getdate(),date_of_marathon)>3 if sex='f') order by Date_of_marathon
Where for the example table above I'd want the answer
Code:
1
3
Any ideas?