如何写入查询在perticuler年中加入了多少个empl [英] How write query for how many empls are joined in the perticuler year

查看:109
本文介绍了如何写入查询在perticuler年中加入了多少个empl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个查询来显示特定年份加入的员工数量



赞1998-6 
2000-8
2012-10



我写的查询显示结果如

 1987 -09-17 00:00:00.000 1 
1989-09-21 00:00:00.000 1
1990-01-03 00:00:00.000 1
1991-05-21 00 :00:00.000 1
1993-01-13 00:00:00.000 1
1994-06-07 00:00:00.000 4
1994-08-16 00:00:00.000 1
1994-08-17 00:00:00.000 1
1994-12-07 00:00:00.000 1





但我想在1994-12-07 - 7这样展示..



 选择 hire_date,count(Employee_Id)
来自 empp
group hire_date





SHOUTING已删除,代码块添加 - OriginalGriff [/ edit]

解决方案

 选择年(hire_date),计算(Employee_Id)
来自 empp
group 按年(hire_date)


您好Chandugg,



请尝试以下解决方案。在这个解决方案中,我创建了一个完整的示例,但您只能看到最终查询。



  -   为员工创建一个表 

创建 empp
(Id int identity 1 1 primary key
Employee_Id int
hire_date datetime


- - 在表格中插入数据

insert into empp(Employee_Id,hire_date)
1 ' 1987-09-17 00:00:00.000'),
1 ' 1989-09-21 00:00:00.000'),
(< span class =code-digit> 1 ,' 1990-01-03 00:00:00.000 '),
1 ' 1991-05-21 00:00:00.000'),
1 ' 1993-01-13 00:00:00.000'),
4 ' 1994-06-07 00:00:00.000'),
1 ' 1994-08-16 00:00 :00.000'),
1 ' 1994-08-17 00:00:00.000'),
1 ' 1994-12-07 00:00:00.000'

- 预期结果的最终查询
选择 DATEPART(yyyy,hire_Date),count(Employee_Id)来自 empp
(DATEPART(yyyy,hire_Date))


I want write a query for displaying how many employees are joined in the particular year

Like    1998-6
        2000-8
        2012-10 


Iam writing query it displays result like

1987-09-17 00:00:00.000 1
1989-09-21 00:00:00.000 1
1990-01-03 00:00:00.000 1
1991-05-21 00:00:00.000 1
1993-01-13 00:00:00.000 1
1994-06-07 00:00:00.000 4
1994-08-16 00:00:00.000 1
1994-08-17 00:00:00.000 1
1994-12-07 00:00:00.000 1



But i want to display in 1994-12-07 - 7 like this..

select  hire_date, count(Employee_Id)
  from  empp
group by hire_date



[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]

解决方案

select year( hire_date), count(Employee_Id)
from empp
group by year( hire_date)


Hi Chandugg,

Please try following solution. In this solution I create a full example but you can see only final query.

--Create a Table for employee

Create Table empp
(Id int identity(1,1) primary key,
Employee_Id int,
hire_date datetime
)

---Insert data in table

insert into empp(Employee_Id,hire_date)
values (1,'1987-09-17 00:00:00.000'),
(1,'1989-09-21 00:00:00.000'),
(1, '1990-01-03 00:00:00.000'),
(1,'1991-05-21 00:00:00.000'),
(1,'1993-01-13 00:00:00.000'),
(4,'1994-06-07 00:00:00.000'),
(1, '1994-08-16 00:00:00.000'),
(1,'1994-08-17 00:00:00.000'),
(1,'1994-12-07 00:00:00.000')

--final query for expected result
Select DATEPART(yyyy,hire_Date), count(Employee_Id) from empp
Group by (DATEPART(yyyy,hire_Date))


这篇关于如何写入查询在perticuler年中加入了多少个empl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆