如何实施一个系统来确定是否已达到里程碑
我有一个名为“统计”的表,
player_id team_id match_date goal assist` 1 8 2010-01-01 1 1 1 8 2010-01-01 2 0 1 9 2010-01-01 0 5 ...
我想知道球员何时达到里程碑(例如 100 个进球、100 个助攻、500 个进球...)
我还想知道团队何时达到里程碑。
我想知道哪个球员或球队第一、第二、第三达到 100 个进球...
我想使用带有表格的触发器来累计总数。
表player_accumulator(和team_accumulator)表将是
player_id total_goals total_assists 1 3 6 team_id total_goals total_assists 8 3 1 9 0 5
每次在统计表中插入一行时,触发器将插入/更新player_accumulator和team_accumulator表。
此触发器还可以验证玩家或团队是否已达到包含数字的里程碑表中的里程碑
milestone 100 500 1000 ...
表player_milestone将包含玩家达到的里程碑:
player_id stat milestone date 1 goal 100 2013-04-02 1 assist 100 2012-11-19
There is a better way to implements a "milestone" ?
There is an easiest way without triggers ?
我正在使用 PostgreSQL
I have a table named stats
player_id team_id match_date goal assist` 1 8 2010-01-01 1 1 1 8 2010-01-01 2 0 1 9 2010-01-01 0 5 ...
I would like to know when a player reach a milestone (eg 100 goals, 100 assists, 500 goals...)
I would like to know also when a team reach a milestone.
I want to know which player or team reach 100 goals first, second, third...
I thought to use triggers with tables to accumulate the totals.
Table player_accumulator (and team_accumulator) table would be
player_id total_goals total_assists 1 3 6 team_id total_goals total_assists 8 3 1 9 0 5
Each time a row is inserted in stats table, a trigger will insert/update player_accumulator and team_accumulator tables.
This trigger could also verify if player or team has reached a milestone in milestone table containing numbers
milestone 100 500 1000 ...
A table player_milestone would contains milestone reached by player:
player_id stat milestone date 1 goal 100 2013-04-02 1 assist 100 2012-11-19
There is a better way to implements a "milestone" ?
There is an easiest way without triggers ?
I'm using PostgreSQL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只计算得分球员以及得分球队的所有进球和助攻。
像这样在客户端(以伪代码):
不要维护里程碑表,因为这会使数据库非规范化。我认为这是一个不成熟的优化。只有当上述确实不够快时(例如,当每个player_id或team_id的统计数据超过几千行时),您才可以考虑维护里程碑表。
I'd just count all goals and assists of a player which scores, and team, which scores.
Like this on client side (in pseudocode):
Do not maintain milestone table, as this makes the database denormalized. I think this is a premature optimization. Only when the above is really not fast enough (for example when stats will have more than few thousands of rows per player_id or team_id) then you can think of maintaining milestone table.