如何获得每年的员工数量

问题描述:

亲爱的,



我有一张名为Mst_Employee的表。字段是


Emp_No >
Emp_Name

Emp_JoiningDate

Emp_ResignedDate

Emp_Status





如何按年份获得员工人数。

每年有人加入或辞职。



例如结果看起来像这样

年-----不。员工。

2011 ---- 125

2012 ----- 130

2013 ----- 100 >


请帮助这个

谢谢

Basit。

Dear,

I have a table called Mst_Employee.Field are

Emp_No
Emp_Name
Emp_JoiningDate
Emp_ResignedDate
Emp_Status


How to get the No. of Employees by Year.
Each year somebody join or resigned.

E.g. Result look like this
Year-----No. of Employees.
2011---- 125
2012-----130
2013-----100

Please help on this
Thanks
Basit.

按功能和计数使用组。



请参阅以下链接

http://www.w3schools.com/sql/sql_groupby.asp [ ^ ]



此网站还将帮助您提取月份部分约会。



首先尝试这个,如果您有其他问题,请告诉我们。
Use a group by function and count.

Refer to the following link
http://www.w3schools.com/sql/sql_groupby.asp[^]

This site will also help you extract out the month part of the date.

Try this first and if you have further issues let us know.


试试这个



try this

select JY,Sum(TotalCount) from (
select JY,Sum(x.CJM) over(order by JY  ROWS UNBOUNDED PRECEDING) as TotalCount from (
select * from (
select Row_Number() over (order by year(Emp_JoiningDate))as ID,year(Emp_JoiningDate)as JY,Count(year(Emp_JoiningDate))as CJM from ##Emp
group by year(Emp_JoiningDate))JoingData
Union ALL
select * from (
select Row_Number() over (order by year(Emp_ResignedDate))as ID,year(Emp_ResignedDate)as JY,-Count(year(Emp_ResignedDate))as CRM from ##Emp
where Emp_ResignedDate is not null group by year(Emp_ResignedDate))ResignedData
) as x )y group by JY


请尝试以下操作。



Try following.

Select year(emp_joiningdate),count(emp_no)
from Mst_Employee 
where emp_resigneddate is null
Group by year(emp_joiningdate) 







如果这不起作用,请回答它给出的问题。




If this doesn't work write me back with the problem it gives.