简体   繁体   中英

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.

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.

Let me clarify:

Three columns:

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
  • You may use FeelingName instead of int ID too, it will just use more space.

在此处输入图片说明


EDIT

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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