Click here to Skip to main content
16,008,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have 2 tables ,

VB
EMPID   Name
1       Raghu
2       Venki


and
ID	EMPID 	Hike salary date	Salary
1       1       Jan 1st 2014    1000
2       2       Jan 1st 2014    1200
3       2     March 1st 2014    1300
4       2      june 1st 2014    1200
5       2       SEP 1st 2014    1600


1> Display employee name ,current salary of each employee,with hike date.
2>Display employee name , count of salary increments for each employee.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 14-Mar-15 2:09am
v2

Try this:
SQL
-- 1)  Display employee name ,current salary of each employee,with hike date.
SELECT E.EmpName, S2.Salary,  S1.Hike_salary_date
FROM Employees AS E INNER JOIN (
    SELECT EMPID, MAX(Hike_salary_date) AS Hike_salary_date
    FROM Salaries
    GROUP BY EMPID
  ) AS S1 ON E.EMPID = S1.EMPID
INNER JOIN Salaries AS S2 ON E.EMPID = S2.EMPID AND S1.Hike_salary_date = S2.Hike_salary_date


-- 2) Display employee name , count of salary increments for each employee.
SELECT E.EmpName, ROW_NUMBER() OVER(PARTITION BY S.EMPID ORDER BY S.Hike_salary_date) AS IncremCountOfSalary
FROM Employees AS E INNER JOIN Salaries AS S ON E.EMPID = S.EMPID


SQLFiddle[^]
 
Share this answer
 
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900