简体   繁体   English

时间表关系数据库设计

[英]Timesheet relational database design

I need to build some queries on top of an existing timesheet database application for project specific purposes. 我需要在现有的时间表数据库应用程序之上构建一些查询,以用于特定于项目的目的。

I can drop out data from the timesheet database of 我可以从时间表数据库中删除数据

USER_ID | ENTRY_DATE | BILLED_HRS

then map it a Project Organisation chart for that the data I have is: 然后将它映射到项目组织结构图,我所拥有的数据是:

USER_ID | PROJECT_ROLE | START_DATE | FINISH_DATE

what the best way to join these two given that START_DATE and FINISH_DATE are the only way to map HRS to PROJECT_ROLE. 在START_DATE和FINISH_DATE之间加入这两者的最佳方法是将HRS映射到PROJECT_ROLE的唯一方法。

Probably only 5-10 USER_IDs would have multiple roles so there maybe a way to fast track this. 可能只有5-10个USER_ID会有多个角色,所以可能有办法快速跟踪这个。 I can't modify the underlying timesheet application tables so this join needs to be fast enough to run regularly. 我无法修改基础时间表应用程序表,因此此连接需要足够快以便定期运行。

thanks 谢谢

The basic query you are looking for is something like: 您正在寻找的基本查询是这样的:

SELECT ts.*, po.project_role
FROM timesheet ts
LEFT JOIN project_organization po ON
   po.user_id = ts.user_id AND
   ts.entry_date BETWEEN po.start_date AND po.finish_date

I would leave a LEFT JOIN so as to be sure you do not loose timesheet data even if you do not match any project_role. 我会留下LEFT JOIN,以确保即使您没有匹配任何project_role,也不会丢失时间表数据。 Be careful though... if the project organization table has rows that overlap start_date and finish_date for the same user_id, you will be getting duplicate timesheet data. 但要小心......如果项目组织表的行与同一user_id的start_date和finish_date重叠,则会得到重复的时间表数据。 And that is not avoidable with an INNER vs OUTER JOIN. 对于INNER和OUTER JOIN,这是不可避免的。

As to the efficiency of this query, it very well depends on the indexes you have. 至于此查询的效率,它很大程度上取决于您拥有的索引。

As a personal suggestion... I'd advise to pull out the data regularly (each night maybe) and make a copy in another db for reporting purposes. 作为个人建议......我建议定期(可能每晚)提取数据并在另一个数据库中复制以用于报告目的。 This way you can check it (showing warnings for data that match no project_role or that match more than one project_role) and cleanse it (writing the project_role found directly on the timesheet data table). 通过这种方式,您可以检查它(显示与没有project_role匹配或匹配多个project_role的数据的警告)并清理它(直接在时间表数据表中写入project_role)。 Of course you cannot do this if you want to run your queries on live data. 当然,如果要对实时数据运行查询,则无法执行此操作。 But I also suppose timesheet data is input no more than once a day, so it could be the best solution. 但我也假设时间表数据每天输入的次数不超过一次,因此它可能是最佳解决方案。

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

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