So, I recently took a test with some higher level SQL problems. I only have what I consider to be an “intermediate” experience in SQL, and I have been working on this for a whole day. I just can't understand.
Here's the problem:
You have a table with 4 columns as such:
EmployeeID int unique
EmployeeType int
EmployeeSalary int
Created date
Purpose: I need to get the difference between the last two EmployeeSalary for any EmployeeType with more than 1 record. This should be done in one statement (subqueries are ok).
Example dataset: http://sqlfiddle.com/#!9/0dfc7
EmployeeID | EmployeeType | EmployeeSalary | Created
-----------|--------------|----------------|--------------------
1 | 53 | 50 | 2015-11-15 00:00:00
2 | 66 | 20 | 2014-11-11 04:20:23
3 | 66 | 30 | 2015-11-03 08:26:21
4 | 66 | 10 | 2013-11-02 11:32:47
5 | 78 | 70 | 2009-11-08 04:47:47
6 | 78 | 45 | 2006-11-01 04:42:55
So, for this dataset, the correct return will be as follows:
EmployeeType | EmployeeSalary
-------------|---------------
66 | 10
78 | 25
10 EmployeeSalary (30 - 20) EmployeeType 66. 25 EmployeeSalary (70-45) EmployeeType 78. EmployeeID 53, .
. ?
!