简体   繁体   English

VB6 ms访问sql查询区分计数两个表

[英]VB6 ms access sql query distinct count two tables

I need to output per a specific employee this data: employee_Id, employee_name, presence.year, presence.month, count(day), sum(work hours), sum(holiday hours), [work hours] - [holiday hours]. 我需要为每个特定的雇员输出以下数据:employee_Id,employee_name,presence.year,presence.month,count(day),sum(work hours),sum(holiday hours),[work hours]-[holiday hours]。 I used this query on vb6 project but it seems not working good: 我在vb6项目上使用了此查询,但似乎无法正常工作:

SELECT
     Employees.Employee_ID AS ID
     , Employees.Full_Name AS Name
     , Presence.Yr AS Year
     , Presence.Mnth AS Month
     , SUM(IIF(Presence.Dy, 1, 0)) Work_Days
     , SUM(IIF(Presence.Hr, Presence.Hr, 0)) AS Work_Hours
     , SUM(IIF(Presence.Holidays, Presence.Holidays, 0)) AS Holidays_Hours
     , SUM(IIF(Presence.Hr, Presence.Hr, 0)) - SUM(IIF(Presence.Holidays, Presence.Holidays, 0) AS Total_Work_Hours
FROM Employees
INNER JOIN Presence ON Presence.Employee_ID = Employees.Employee_ID
WHERE Employees.Company = 'aCompany'
     AND Employees.Employee_ID = 'anEmmployee'
GROUP BY  Employees.Employee_ID, Employees.Full_Name, Presence.Yr, Presence.Mnth

Like this in the picture: http://oi60.tinypic.com/122c6xz.jpg 像这样的图片: http : //oi60.tinypic.com/122c6xz.jpg

Can anyone help with this? 有人能帮忙吗?

Here is your query with some adjustments: 这是经过一些调整的查询:

SELECT
     Employees.Employee_ID AS ID
     , Employees.Full_Name AS Name
     , Presence.Yr AS Year
     , Presence.Mnth AS Month
     , SUM(IIF(Presence.Dy, 1, 0)) Work_Days
     , SUM(IIF(Presence.Hr, Presence.Hr, 0)) AS Work_Hours
     , SUM(IIF(Presence.Holidays, Presence.Holidays, 0)) AS Holidays_Hours
     , SUM(IIF(Presence.Hr, Presence.Hr, 0)) - SUM(IIF(Presence.Holidays, Presence.Holidays, 0) AS Total_Work_Hours
     , SUM(Presence.Hr) / Employees.HoursPerDay + Employees.TotalAnnualHolidays - Employees.DoneHolidays AS AvailableHolidays
FROM Employees
INNER JOIN Presence ON Presence.Employee_ID = Employees.Employee_ID
WHERE Employees.Company = 'aCompany'
     AND Employees.Employee_ID = 'anEmmployee'
GROUP BY  Employees.Employee_ID, Employees.Full_Name, Employees.HoursPerDay, Employees.TotalAnnualHolidays, Employees.DoneHolidays, Presence.Yr, Presence.Mnth

Can you test this new query and give me info about the result and the difference with what you're looking for? 您可以测试这个新查询,并向我提供有关结果以及与您所寻找的差异的信息吗?

Hope this will help. 希望这会有所帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM