Given this sample fiddle containing sales value and date for two users: http://sqlfiddle.com/#!2/8148be/3
How can I find the first user who has reached a total saleValue
of 30 since the beginning of 2001?
The background: assume there is a contest running from date X, which ends the moment someone passes a specific threshold of sale value, and that person becomes the sole winner. There can be multiple contest running at the same time, so it is not feasible to check for winner in all contest when inserting new sales into the database.
Best Answer
First you will need a table with a column representing how many sales a seller has accumulated at a certain point in time:
The rest is easy:
SQL Fiddle