目标:从头开始创建员工流动报告

发布于 2025-01-08 03:48:25 字数 1996 浏览 1 评论 0原文

我需要创建员工流动报告,该报告应根据参数化的时间段显示以下信息:

  1. 当前员工
  2. 首发
  3. 人员离职
  4. 人员 经理
  5. 合同站点

目前,我有一些如何获取报告的想法。创建缓慢变化的维度,或者复制每个期间的员工表快照,或者针对每个工资运行分别跟踪入职者和离职者。我尝试过慢慢改变尺寸,它对新初学者来说效果很好;然而,它对离职者来说却失败了。我不确定跟踪每个薪资的入职者和离职者是否有效。

创建了下表作为解决方案的开始

我在 MS SQL 2008 业务中相对较新。请注意。主要目标是确定员工流失率最高的管理人员和签约地点。

注释 -目前,我没有使用任何特定的技术并正在寻找解决方案。

-我确实打算为了报告的目的建立和设计一个全新的数据库。我所说的数据库是指 CRM 数据库 (SQL 2008) 上的一些表的集合。 表格集合我指的是经理的“维度”表格、签约站点的“维度”表格以及员工表格。所以目前,我认为我的解决方案应该至少有3个表;然而,我的技能并没有那么好解决这个难题。

我认为上面的表格可以让我编写一个 SQL 查询来比较不同时期并获得所需的结果。

payno depcod ID 导入

12568 EDE322001 12568EDE322001A 2011 年 12 月 31 日

12568 EDE322001 12568EDE322001B 2011 年 12 月 31 日

16822 EDE322001 16822EDE322001A 31 2011年12月

17694 EDE322001 17694EDE322001A 2011年12月31日

12568 EDE322001 12568EDE322001A 2012年1月4日

12568 EDE322001 12568EDE322001B 1月4日2012

16822 EDE322001 16822EDE322001A 2012 年 1 月 4 日

17694 EDE322001 17694EDE322001A 2012 年 1 月 4 日

12568 EDE322001 12568EDE322001A 1 月 31 日2012

年 12568 EDE322001 12568EDE322001B 2012年1月31日

16822 EDE322001 16822EDE322001A 2012年1月31日

17694 EDE322001 17694EDE322001A 1月31日2012

年 17661 EDE322001 17661EDE322001A 2012年1月31日

12568 EDE322001 12568EDE322001A 2012年2月1日

12568 EDE322001 12568EDE322001B 2月1日2012

16822 EDE322001 16822EDE322001A 2012 年 2 月 1 日

17906 EDE322001 17906EDE322001A 2012 年 2 月 1 日

17907 EDE322001 17907EDE322001A 2 月 1 日2012

年 12568 EDE322001 12568EDE322001A 2012年2月29日

12568 EDE322001 12568EDE322001B 2012年2月29日

17907 EDE322001 17907EDE322001A 2月29日2012

上表是快照表。快照日期显示在导入列中。 (凌乱表格的应用徽标;我不知道如何制作表格)现在我需要找到一种方法来将一个日期与另一个日期进行比较(最好在循环中)以找出第一个日期和下一个日期之间的差异。

例如,17661 EDE322001 17661EDE322001A 31 January 2012 是新员工,16822 EDE322001 16822EDE322001A 01 February 2012 是离职员工。

非常感谢

I have a requirement to create staff turnover report that should display following information according to parameterized period:

  1. current staff
  2. starters
  3. leavers
  4. manager
  5. contracted site

Currently, I have a few ideas how to get a report. Either create slowly changing dimension or copy snapshots of employees table for each period or track starter and leavers seperately for each payrun. I have tried slowly changing dimension and it did fine job on new starters; however, it failed on leavers. I am not sure if tracking starters and leaver for each payruns would work.

Created a table below as a start of solution

I am relatively new in MS SQL 2008 business. Please adise. The main goal is to identify managers and contracted sites with highest staff turnover.

Notes
-Currently, I am not using any specific techonlogy and looking for solution.

-I do intend to build and design a brand new database for the sake of the report. By database I mean a few collection of tables that sit on CRM database (SQL 2008). By Collection of tables I mean "dimension" table for managers, "dimension" table of contracted sites, and a table of staff. So currently, I think that my solution should have at least 3 tables; however, my skills are not that good to solve the puzzle.

I think that have tables above would let me to write a SQL query that could compare different periods and get required results.

payno depcod Idd Imported

12568 EDE322001 12568EDE322001A 31 December 2011

12568 EDE322001 12568EDE322001B 31 December 2011

16822 EDE322001 16822EDE322001A 31 December 2011

17694 EDE322001 17694EDE322001A 31 December 2011

12568 EDE322001 12568EDE322001A 04 January 2012

12568 EDE322001 12568EDE322001B 04 January 2012

16822 EDE322001 16822EDE322001A 04 January 2012

17694 EDE322001 17694EDE322001A 04 January 2012

12568 EDE322001 12568EDE322001A 31 January 2012

12568 EDE322001 12568EDE322001B 31 January 2012

16822 EDE322001 16822EDE322001A 31 January 2012

17694 EDE322001 17694EDE322001A 31 January 2012

17661 EDE322001 17661EDE322001A 31 January 2012

12568 EDE322001 12568EDE322001A 01 February 2012

12568 EDE322001 12568EDE322001B 01 February 2012

16822 EDE322001 16822EDE322001A 01 February 2012

17906 EDE322001 17906EDE322001A 01 February 2012

17907 EDE322001 17907EDE322001A 01 February 2012

12568 EDE322001 12568EDE322001A 29 February 2012

12568 EDE322001 12568EDE322001B 29 February 2012

17907 EDE322001 17907EDE322001A 29 February 2012

Table above is table of snapshots. Snapshot date is displayed in Imported Column. ( Applogoes for messy table; I could not figure out how to make a table) Now i need to find a away how to compare one date to another (ideally in the loop) to figure out the difference between 1st date and following date.

For instance, 17661 EDE322001 17661EDE322001A 31 January 2012 is a new staff and 16822 EDE322001 16822EDE322001A 01 February 2012 is a leaver.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事还在继续 2025-01-15 03:48:25

考虑到所有关于缓慢改变维度等的讨论,我可能把这个问题看得太简单了,但是简单的旧 SQL 有什么问题呢?我假设您有一个包含 Manager、ContractedSite、StartDate 和 EndDate 字段的 Employee 表。

您需要以下人员:

  • 现任员工。该电流是在周期开始时还是在周期结束时还是在周期内的某个时间活跃?
  • 首发。 StartDate 大于或等于期间开始但小于或等于期间结束的人员。
  • 离校者。 EndDate 大于或等于期间开始但小于或等于期间结束的人员。
  • 周转。这让我们回到了“现任员工”的含义。流动率本质上是期初现有员工与期末现有员工之间的差异,以原始数字或百分比表示。因此,期间开始时的当前员工是 StartDate 小于期间开始且没有 EndDate 或 EndDate 大于或等于期间开始的人员。期末的现有工作人员情况也是如此。

因此,您需要从数据中提取一些特定案例:

SELECT Manager, ContractedSite, 
    SUM(CASE WHEN StartDate < @PeriodStart AND ((EndDate IS NULL) OR (EndDate >= @PeriodStart)) THEN 1 END) AS OpeningStaff,
    SUM(CASE WHEN StartDate >= @PeriodStart AND StartDate <= @PeriodEnd THEN 1 END) AS Starters,
    SUM(CASE WHEN EndDate >= @PeriodStart AND EndDate <= @PeriodEnd) THEN 1 END) AS Leavers,
    SUM(CASE WHEN StartDate <= @PeriodEnd AND ((EndDate IS NULL) OR (EndDate > @PeriodEnd)) THEN 1 END) AS ClosingStaff
FROM Employee
WHERE (StartDate <= @PeriodEnd) AND ((EndDate IS NULL) OR (EndDate >= @PeriodStart))
GROUP BY Manager, ContractedSite
ORDER BY Manager, ContractedSite

现在您只需计算报告中 OpeningStaff 和 ClosingStaff 之间的差异即可获得营业额,然后就完成了。

I may be looking at this too simplistically given all the talk about slowly changing dimensions, etc, but what's wrong with a plain old bit of SQL? I'm going to assume you have an Employee table with Manager, ContractedSite, StartDate and EndDate fields.

You want the following:

  • Current staff. Is this current at the start of the period or at the end of the period or active at some time during the period?
  • Starters. People who have a StartDate greater than or equal to the start of the period but less than or equal to the end of the period.
  • Leavers. People who have an EndDate greater than or equal to the start of the period but less than or equal to the end of the period.
  • Turnover. Which brings us back to what you mean by "Current staff". Turnover is essentially the difference between the current staff at the start of the period and the current staff at the end of the period, expressed either as a raw number or a percentage. So current staff at the start of the period are people with a StartDate less than the period start and either no EndDate or an EndDate greater than or equal to the start of the period. Similarly with the current staff at the end of the period.

So you have some specific cases to extract from your data:

SELECT Manager, ContractedSite, 
    SUM(CASE WHEN StartDate < @PeriodStart AND ((EndDate IS NULL) OR (EndDate >= @PeriodStart)) THEN 1 END) AS OpeningStaff,
    SUM(CASE WHEN StartDate >= @PeriodStart AND StartDate <= @PeriodEnd THEN 1 END) AS Starters,
    SUM(CASE WHEN EndDate >= @PeriodStart AND EndDate <= @PeriodEnd) THEN 1 END) AS Leavers,
    SUM(CASE WHEN StartDate <= @PeriodEnd AND ((EndDate IS NULL) OR (EndDate > @PeriodEnd)) THEN 1 END) AS ClosingStaff
FROM Employee
WHERE (StartDate <= @PeriodEnd) AND ((EndDate IS NULL) OR (EndDate >= @PeriodStart))
GROUP BY Manager, ContractedSite
ORDER BY Manager, ContractedSite

Now you just need to calculate the difference between OpeningStaff and ClosingStaff in your report to get the turnover and you're done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文