SQL summing with difference -


I have a SQL Server query:

  select ep.employeeID, ep. Join punchdate, rc.creditAmount EmployeePunch EP, at ResponderCredit rc rc.employeeID = ep.employeeID and rc.punchdate = rc.creditdate command by ep.employeeID  

and get a result set :

  Employed Debt Credit Amount ----------- ------- -------------- 5 01 / 01/2007 5 5 03/01/2007 7 5 04/22/2007 15 6 01/01/2007 3 6 01/12/2007 4  

And I am an amphiIid and a credit amount I want the group. The catch is that I need a change in the credit amount between the maximum and the minimum date:

  Employee credit credit ----------- ------ ------- 5 10 6 1  

How can I do this?

in oracle:

  select r1.employeeID, amMax - from AmMin (Selection EmployeeID, from AmMin (Selection ROW_NUMBER ()) (by EP.EmployeeID by RC PARTITION .creditdate) as rnMin, ep.employeeID, rc.creditAmount ammon as EmployeePunch EP, ResponderCredit Rc where rc.employeeID = ep.employeeID and rc.punchdate = rc.creditdate) Where rn_min = 1) r1, (Select EmployeeID, from AmMin (select ROW_NUMBER ()) (RC credit digit for compliance by RPCMX APMX by DESC), AP Employee, Rc.creditAmou Nt EmployeePunch from EP as amMax, ResponderCredit Rc where rc.employeeID = ep.employeeID and rc.punchdate = rc.creditdate) Where rn_max = 1) r2 Where r1.employeeID = r2.employeeID  

Comments