由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请教一个表的设计问题
相关主题
服了,这就是我们QA和DBA的水平怎么在Access 97中自动更新日期?
Pivot table IS WONDERFUL两个Excel上的问题
我来考你们一下请问如何算出这个天数来
如何完成这个sql?sql question
我也问一个sql querry的问题sql query question
这个query怎么写?谢谢请教大虾问题哈,包子谢哈
sql server 行转列的问题How to find intersection of two tables
How did they track the article status in this BBS?咋查Oracle job的status呀?
相关话题的讨论汇总
话题: status话题: date话题: 2013话题: table话题: 设计
进入Database版参与讨论
1 (共1页)
tj
发帖数: 957
1
美国有两千万移民,现在需要个表存所有人的状态。从这个表中需要能知道任何一天每
个人的状态。
如果需要每天更新大量的数据,怎么设计才能实现快速读/写?
这两个都各有利弊,有没有别的方案?
person_id, status_id, status_date.
1, 1, 1/1/2013
1, 2, 3/1/2013
2
person_id, status_id, status_from_date, status_thru_date.
1, 1, 1/1/2013, 2/28/2013
1, 2, 3/1/2013, null
s**********o
发帖数: 14359
2
也有3,跟2相似,2个TABLE,status_thru_date有值的进入ARCHIVE TABLE
person_id, status_id, status_from_date, status_thru_date.
1, 1, 1/1/2013, 2/28/2013
CURRENT TABLE只保留
person_id, status_id, status_from_date
1, 2, 3/1/2013
因为读取的时候通常只关心现在的STATUS,所以只需要CURRENT TABLE
找HISTORY的时候再去ARCHIVE TABLE。
tj
发帖数: 957
3
多谢。这个对只查当前值的情况非常好。但是如果查昨天的,就要搜两个了?

【在 s**********o 的大作中提到】
: 也有3,跟2相似,2个TABLE,status_thru_date有值的进入ARCHIVE TABLE
: person_id, status_id, status_from_date, status_thru_date.
: 1, 1, 1/1/2013, 2/28/2013
: CURRENT TABLE只保留
: person_id, status_id, status_from_date
: 1, 2, 3/1/2013
: 因为读取的时候通常只关心现在的STATUS,所以只需要CURRENT TABLE
: 找HISTORY的时候再去ARCHIVE TABLE。

s**********o
发帖数: 14359
4
昨天的STATUS是要两个表都去找,但
谁会经常去查哪一年哪一天的STATUS,
这个要求挺高,我要查你20年某一天的STATUS,
这个多数数据库都做不了的,多数情况都是当前的
而且STATUS即状态都是现在的,比如MARITAL STATUS
婚姻状况,去问昨天是不是MARRIED基本没有意义的

【在 tj 的大作中提到】
: 多谢。这个对只查当前值的情况非常好。但是如果查昨天的,就要搜两个了?
tj
发帖数: 957
5
20年不至于。但是查昨天,上星期,或者几个月年前的状态是必须的。
比如说美国政府的信用级别是AA,但是2011年前是AAA。这个是有可能不断变化的。假
如你上个月买了美国国库券,今天想《《计算》》你买的是不是合适的,你就必须要知
道你买的那天他的信用级别。

【在 s**********o 的大作中提到】
: 昨天的STATUS是要两个表都去找,但
: 谁会经常去查哪一年哪一天的STATUS,
: 这个要求挺高,我要查你20年某一天的STATUS,
: 这个多数数据库都做不了的,多数情况都是当前的
: 而且STATUS即状态都是现在的,比如MARITAL STATUS
: 婚姻状况,去问昨天是不是MARRIED基本没有意义的

k*z
发帖数: 4704
6
我们公司的状态表是这么设计的
asset, activate_date, deactivate_date, status.
tj
发帖数: 957
7
这个好像和我的第二个表一样。
问题是查询的时候会不会比较慢?
For example, assume min/max_date defined, to find status for all assets as
of 9/1/2013?
select asset, activate_date, deactivate_date, status
from asset_statuses
where to_date('1-sep-2013') between nvl(activate_date, min_date) and nvl(
deactivate_date, max_date)

【在 k*z 的大作中提到】
: 我们公司的状态表是这么设计的
: asset, activate_date, deactivate_date, status.

s**********o
发帖数: 14359
8
世界上没几个国家的吧,你那个比如美国没有几个RECORD的了,
你要把它推广到每个人数据量就大了,
设计表之前就要考虑,到底要保持多少年的STATUS,不能有
含糊,是多少年就是多少年,否则你的数据库搞得就很业余。
假设你要给中国政府搞个中国每个人的工作状态,每个人
一换工作就要更新,都存在一个表里,你这个数据就海量了

【在 tj 的大作中提到】
: 20年不至于。但是查昨天,上星期,或者几个月年前的状态是必须的。
: 比如说美国政府的信用级别是AA,但是2011年前是AAA。这个是有可能不断变化的。假
: 如你上个月买了美国国库券,今天想《《计算》》你买的是不是合适的,你就必须要知
: 道你买的那天他的信用级别。

d****n
发帖数: 12461
9
特别是某人经常更新某人一直不更新就凌乱了。

【在 s**********o 的大作中提到】
: 世界上没几个国家的吧,你那个比如美国没有几个RECORD的了,
: 你要把它推广到每个人数据量就大了,
: 设计表之前就要考虑,到底要保持多少年的STATUS,不能有
: 含糊,是多少年就是多少年,否则你的数据库搞得就很业余。
: 假设你要给中国政府搞个中国每个人的工作状态,每个人
: 一换工作就要更新,都存在一个表里,你这个数据就海量了

tj
发帖数: 957
10
Well, this is a tech question. And it is applicable to real world problems.
Maybe the example I gave was not particularly good. Yes there are only a
couple hundreds of countries. But, municipals as well as corporations can
have credit ratings, and there are a few rating agencies, among them 4 or 5
are frequently used. So data volume can really grow.
Or, think about it this way. Everyone has a credit score. A credit card
company may obtain that info and store in its database regardless of whether
you have a card with them or not. And they have data feeds to update this
data. They want to search for potential customers and send out junk mails.
Maybe this is another bad example that you can argue it's of no use. My
point is really trying to pull back to the tech part of the question.

【在 s**********o 的大作中提到】
: 世界上没几个国家的吧,你那个比如美国没有几个RECORD的了,
: 你要把它推广到每个人数据量就大了,
: 设计表之前就要考虑,到底要保持多少年的STATUS,不能有
: 含糊,是多少年就是多少年,否则你的数据库搞得就很业余。
: 假设你要给中国政府搞个中国每个人的工作状态,每个人
: 一换工作就要更新,都存在一个表里,你这个数据就海量了

s**********o
发帖数: 14359
11
就用你举得信用的例子,信用公司只会给你现在的信用SCORE,
不会给你10年前的CREDIT SCORE,要调出10年前的需要SPECIAL REQUEST,
银行也是这样,给你三个月的STATEMENT ONLINE,想要老的就要交钱
去ARCHIVE给你RUN。设计数据库之前就要考虑有多少RECORD,10年20
年会增加到多少。这不是TECHINICAL的问题,是BUSINESS的问题。

.
5
whether

【在 tj 的大作中提到】
: Well, this is a tech question. And it is applicable to real world problems.
: Maybe the example I gave was not particularly good. Yes there are only a
: couple hundreds of countries. But, municipals as well as corporations can
: have credit ratings, and there are a few rating agencies, among them 4 or 5
: are frequently used. So data volume can really grow.
: Or, think about it this way. Everyone has a credit score. A credit card
: company may obtain that info and store in its database regardless of whether
: you have a card with them or not. And they have data feeds to update this
: data. They want to search for potential customers and send out junk mails.
: Maybe this is another bad example that you can argue it's of no use. My

1 (共1页)
进入Database版参与讨论
相关主题
咋查Oracle job的status呀?我也问一个sql querry的问题
大家帮忙看看这个oracle statement, 怎么总是报错?这个query怎么写?谢谢
再请教大牛一个问题sql server 行转列的问题
求教一个mysql的select优化How did they track the article status in this BBS?
服了,这就是我们QA和DBA的水平怎么在Access 97中自动更新日期?
Pivot table IS WONDERFUL两个Excel上的问题
我来考你们一下请问如何算出这个天数来
如何完成这个sql?sql question
相关话题的讨论汇总
话题: status话题: date话题: 2013话题: table话题: 设计