简体   繁体   English

数据库设计留出时间

[英]Database design to allow for time

So, I want a table of data I have to be represented in time. 因此,我想要一个必须及时表示的数据表。

That is, I want to collect the data over time and have it record when that is. 就是说,我想随着时间的推移收集数据并记录下来。

Currently, the table has an id, a column with a category name, and a column for a value. 当前,该表具有一个ID,一个带有类别名称的列和一个用于值的列。

There are about ten categories - each of them has a value associated with the number of occurrences right now. 大约有十个类别-每个类别都有一个与当前发生次数相关的值。

What's the most efficient way to denote time in this circumstance? 在这种情况下表示时间的最有效方法是什么? Assign a timestamp column to each row? 为每一行分配一个时间戳列? And then when I want to show this information, merely collect via timestamp? 然后,当我想显示此信息时,仅通过时间戳收集? I'm really flying blind here. 我真的在这里瞎瞎了。

Would this require having multiple, repeated values of the category column? 这会要求类别列具有多个重复的值吗?

This is all in MySQL. 这一切都在MySQL中。

Let me clarify: 让我澄清一下:

Three columns: 三栏:

ID | ID | Category | 分类| Value

I want to record the values over time - I am going to be making a parse once per hour. 我想记录一段时间内的值-我将每小时进行一次解析。

The categories will be like: 类别如下:

Happy 快乐

Sad 伤心

Angry 愤怒

etc 等等

How do I record time data with this? 如何以此记录时间数据? I want to keep the values per hour. 我想保留每小时的值。

I was thinking about just repeating all of the categories with timestamp data. 我正在考虑仅使用时间戳数据重复所有类别。 Would that be the best idea? 那是最好的主意吗?

So you'd have 所以你有

Category | Value |  Time
Happy    |    0  |  072012
Happy    |    2  |  072112
Happy    |    1  |  072212

etc - this is what I'm thinking should be done to store constantly changing data. 等等-这就是我想存储不断变化的数据的方法。

What is the timestamp, data related to the category or a child of the category? 什么是时间戳,与类别相关的数据或该类别的子级? If it is related to the category then adding a timestamp field to the category is probably best. 如果与类别有关,则最好在类别中添加一个时间戳字段。 If it is a concept that is now (or in the future) related to transactions in the child (so child would already have this info), I'd probably use a query/view (or a materialized view if there were performance issues). 如果这个概念现在(或将来)与子项中的事务相关(因此子项将已经有此信息),那么我可能会使用查询/视图(如果存在性能问题,则使用物化视图) 。 It might also depend on how often you see that timestamp changing and likely data access requirements on subordinate tables. 它还可能取决于您看到时间戳更改的频率以及从属表上可能的数据访问要求。

  • MeasuredAt is the timestamp MeasuredAt是时间戳
  • You may use FeelingName instead of int ID too, it will just use more space. 您也可以使用FeelingName而不是int ID ,它将使用更多空间。

在此处输入图片说明


EDIT 编辑

在此处输入图片说明

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

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