简体   繁体   English

如何计算当月的员工读数

[英]How to count employee readings in current month

I'm trying to work out how to make this view for my database 我正在尝试找出如何为我的数据库创建此视图

The number of meters read in the current month by each of the meter readers (this view should be able to be used at any time without having to be changed to accommodate the date). 每个抄表员在当月读取的抄表数量(该视图应该可以随时使用,而不必更改以适应日期)。

The main trouble I'm having is counting how many times the employee has read a meter in the month. 我遇到的主要麻烦是计算该员工该月读过电表的次数。 I'm using oracle and sql developer. 我正在使用oracle和sql开发人员。

These are my tables: 这些是我的表:

a2_METERREADER

 - EMPLOYEEID
 - FIRSTNAME
 - LASTNAME

a2_READING

 - READINGID
 - METERID
 - EMPLOYEEID
 - BILLNUMBER
 - READING
 - DATERECORD

a2_Watermeter

 - METERID
 - ADDRESS
 - SUBURB
 - POSTCODE
 - STATUS
 - CUSTOMERID
 - REPLACE
 - INSTALLDATE

You need to join the meter reader and reading tables and count the number of rows, grouped by employee for the month in question. 您需要加入抄表器和读取表并计算行数,该行是按雇员在相关月份进行分组的。

Something along these lines: 遵循以下原则:

SELECT reader.EMPLOYEEID, COUNT(reading.READINGID)
FROM a2_METERREADER reader, a2_READING reading
WHERE reader.EMPLOYEEID = reading.EMPLOYEEID
AND YEAR(reading.DATERECORD) = YEAR(SYSDATE)
AND MONTH(reading.DATERECORD) = MONTH(SYSDATE)
GROUP BY reader.EMPLOYEEID

IF your daterecord is a DATE then to access current month from Windows you can do this. 如果您的日期记录是DATE,则可以从Windows访问当前月份。

SELECT EMPLOYEEID, COUNT(*)
FROM a2_READING
WHERE TO_CHAR(DATERECORD, 'MM/YYYY') = TO_CHAR(SYSDATE, 'MM/YYYY')
GROUP BY EMPLOYEEID

This way you eliminate the days from DATERECORD (only keeps months and year) and it has to be the same with the SYSDATE (Current Date) again converted to keep month and year. 这样,您就可以消除DATERECORD中的日期(仅保留月份和年份),并且必须与再次转换为保留月份和年份的SYSDATE(当前日期)相同。

You dont need to join with METERREADER table if you only need the IDs 如果只需要ID,则不需要与METERREADER表联接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取表 1 中当前月份的 ID 计数,这些 ID 也存在于表 2 中的当前月份或当前月份 + 1 或当前月份 + 2 - How to get the count of IDs in table 1 for current month which are also present in table 2 for current month or current month + 1 or current month + 2 如何创建视图表以显示同一员工的当前记录数和总数? 甲骨文 - How do i create a view table to show current number of record of the same employee and the total count? SQL ORACLE mysql 中的当前月份日期时间计数 - Current month datetime count in mysql 计算当前月份的ID - Count IDs from current month 我想将下个月员工工资表更新为当前表 - I want to update next month employee salary table to current table 如何获取自当月开始以来添加的记录数 - How to get count of records added since the start of the current month 计算每个员工在一个月内度假的天数SQL Server - Count number of days each employee take vacation in a month SQL Server 每月获取活跃员工人数的最佳方法是什么? - What is the best way to get active employee count per month? 如何在一个月内明智地显示员工状态 - How to display employee status day wise in a month 如何在绩效体系中统计员工的褒奖和惩戒 - How to count felicitation and discipline of employee in achievements system
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM