Say I have a table that keeps track of the employees my business hires, including the date they are hired and the salaries they are paid. What I'm trying to do is write a query that will tell me which employee it was I hired that took the total amount of money I pay in salaries over a certain threshold.
E.g. my threshold is $100,000 for salaries, I hire Employee A and pay him/her $50,000; a week or two later I hire employee B on a salary of $70,000. So in this case it is Employee B that took me past my threshold.
Say our employee table looks like this:
CREATE TABLE Employees( employeeName varchar(100), datehired datetime, salary money)
Any idea how I would write a query to do this. NOTE that I'm not interested writing a loop or using a cursor to look at each row to determine this.