如何在每月创建数据库表插入数据,包括计算

时间:2018-03-11 15:53:20

标签: database phpmyadmin

我正在创建一个系统,员工可以每月提交高尔夫球场维护工作的评估标记。在每个洞中进行评估。标记将在每个洞中插入1到5个标记。

该栏目是工作类别,工作,频率,洞1,洞2,洞3,洞4。

此外,工作类别,工作,频率可以插入新的,如果需要可以由用户更新。

在评估标记后,需要计算每个孔的工作量已经完成百分比。我决定将所有工作分成多少分数。

但是,我的问题在于DB Design,我不知道如何设计它以使其工作。

到目前为止,我的想法是:

(编号varchar(5),JobCategory varchar(15),JobLocation Varchar(15),Hole1 int,Hole2 int,Hole3 int,Hole4 int,Hole5 int,Marks int)

但我如何按月记录? 因为我已经键入了所有类别,作业,频率左洞(标记)仅由用户输入 enter image description here

我需要输入这样的标记 enter image description here

有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

听起来您的数据库设计有点令人困惑。 您可能最好使用单个表并为每个条目添加时间变量

如果我理解正确,它应该是这样的:

people (table)
    id (int)    
    JobCategory (int id with reference to other table) (or varchar if there's few entries)
    JobLocation (int id with reference to other table) (or varchar if there's few entries)

games (table)
    id (each game has it's own id)
    person (id of the person, referencing people table)
    Hole1-5 (multiple columns)
    Marks (int)
    *timestamp (to record the time)
    *month (if you'll never need data beyond the month)

这样你可以GROUP BY月(或使用更复杂的时间戳查询

虽然如果你真的想保留当前的结构,那么每个表都需要很多JOIN语句。

我希望这有点帮助。我仍然对你准备做的事情感到有些困惑。