属性可以指定一张表而不是另一张表吗?

发布于 2024-08-15 13:09:40 字数 1190 浏览 5 评论 0原文

我正在创建一个体育统计数据库。有了它,我想对许多类型的运动的比赛/比赛统计数据进行分类。例如,该数据库可以告诉您卡罗莱纳黑豹队在 09-10 赛季(橄榄球)中获得了多少次达阵,或者迈阿密热火队在上一场比赛(篮球)中罚球了多少次。

我在设计一种名为“匹配”的更基本的表时遇到了麻烦。比赛表包含以下列:

  • ID (PK match_id)
  • 比赛日期 (play_date)
  • 涉及球队表现的 ID (FK team_1_performance_idteam_2_performance_id)在表现表中。

表现表包含:

  • ID (PK perf_id)
  • 团队 ID (FK team_id)
  • 最重要的是,所有其他统计数据如: 击球次数(*)
  • 每次比赛的平均冲球码数 (*)
  • 三分球命中率 (*)

(*) 问题是,如何使表现表与相应的运动相关?例如,棒球比赛有好球,但足球和曲棍球没有(我能想到的任何其他运动也没有)。我不希望我的绩效表有一个罢工列,因为它只与部分记录相关。

或者我也这样?也许我的设计应该完全不同?你会怎么做呢?

现在,我不知道这是否可行,但我的一个想法是在“匹配”中包含某种引用不同性能表的性能表 ID 列。这样当我查询一场比赛的表现时,它会查看特定的表。这就是这个问题的标题的来源(属性可以指定一个表而不是另一个表吗?)。想象一下“SELECT team_1_performance.strikes FROM Matches INNER JOINproperty_performance_table AS team_1_performance WHERE Matches.performance_table_id = 'Baseball'”如果可能的话,我如何指定property_performance_table?

我的另一个想法是为所有运动创建比赛表,例如 Rugby_Matches 或 Football_Matches,然后为这些运动创建相应的表现表,例如 Rugby_Perfomances 或 Football_Performances。这看起来就像很多代表相似事物的表格。

如果可以的话,尽量让你的回答保持 MySQL 具体。

谢谢!

I'm creating a sports statistics database. With it, I'd like to catalog game/match statistics for many types of sports. For example, this database would be able to tell you how many touchdowns the Carolina Panthers scored in the 09-10 season (football), or how many free throws were made by the Miami Heat in their last game (basketball).

I'm having trouble designing one of the more fundamental tables called Matches. The Matches table has columns for:

  • ID (PK match_id)
  • date of play (play_date)
  • IDs referring to the performances of the teams (FK team_1_performance_id and team_2_performance_id) in table Performances.

The Performances table holds:

  • ID (PK perf_id)
  • team ID (FK team_id)
  • And most importantly, all the other stats like: number of strikes (*)
  • average rushing yards per play (*)
  • percent of 3-pointers made (*)

(*)The problem is, how can I make the Performances table relevant to the respective sport? For example, baseball games have strikes, but soccer and hockey do not (nor does any other sport I can think of). I don't want my Performance table to have a column for strikes when its only going to be relevant for a portion of records.

Or do I? Perhaps my design should be different all together? How would you go about this?

Now, I don't know if this is possible, but one idea I had was to maybe include some kind of perfomance table ID column in Matches that refers to different performance tables. So that when I query a match's performances, it will look at a specific table. This is where the title of this question comes from (Can an attribute designate one table over another?). Imagine "SELECT team_1_performance.strikes FROM Matches INNER JOIN appropriate_performance_table AS team_1_performance WHERE Matches.performance_table_id = 'Baseball'" How could I designate appropriate_performance_table, if that's even possible?

And another idea I had was to create matches tables for all the sports, like Rugby_Matches or Football_Matches, and then respective performance tables for those sports, like Rugby_Perfomances or Football_Performances. This just seems like a lot of tables that represent somewhat similar things.

If you can, try to keep your responses MySQL specific.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

明媚如初 2024-08-22 13:09:40

创建向下的数据,而不是交叉。

因此,性能表

  • 包含: ID (PK perf_id)
  • 团队 ID (FK team_id)
  • 性能统计类型
  • 性能统计值

或类似的内容。

然后,您还必须创建一个规则表,将特定的表现统计类型链接到特定的运动类型

这还允许您轻松添加新的性能统计类型,而不会严重影响您的数据库架构。

然后,如果您愿意,您还可以实施显示顺序,甚至显示分组。

Instead of accross, create the data going down.

So you would have

The Performances table holds:

  • ID (PK perf_id)
  • team ID (FK team_id)
  • Performance Stat Type
  • Performance Stat Value

Or something like that.

You will then also have to create a Rules table, that will link specific Performance Stat Types to specific Sport Types.

This will then also allow you to easily add new Performance Stat Types without majorly impacting your database schema.

You can then also implement display orders, or even display groupings if you like.

二货你真萌 2024-08-22 13:09:40

创建一个“指标”(或“统计”)表,定义您将测量的不同事物。

  Table Metrics
    MetricId int,
    MetericName (Runs Batted In, Touchdowns, FreeThrows, etc.)
    MetricAbbreviation Nullable?
    Sport (That Metric belongs to )

然后您的 MatchStatistics 表将具有

  Table MatchStatistics
    MatchId   
    MetricId
    MetricValue Decimal

该表上的 PK 将是 MatchId 和 MetricId。
您还可以有一个看起来类似的 PlayerStatistics 表,只不过它有 PlayerId 而不是 MatchId

Create a "Metrics" (or "Stats") table, that defines the different things you will measure.

  Table Metrics
    MetricId int,
    MetericName (Runs Batted In, Touchdowns, FreeThrows, etc.)
    MetricAbbreviation Nullable?
    Sport (That Metric belongs to )

Then your MatchStatistics table will have

  Table MatchStatistics
    MatchId   
    MetricId
    MetricValue Decimal

The PK on this table would be MatchId and MetricId.
You could also have a PlayerStatistics Table that would look similar, except it would have PlayerId instead of MatchId

东京女 2024-08-22 13:09:40

您创建运动专用桌子的想法通常会被实现。

Your idea to create sports-specific tables is generally what is done.

泡沫很甜 2024-08-22 13:09:40

如果您选择阿斯坦德,那么您需要查询卡罗莱纳州的所有胜利,其中达阵得分多于拦截。

如果你以正确的方式做到了,在列中,你会

SELECT * FROM Football_stats  fs
WHERE fs.team_fk = (something that resolves to Carolina)
fs.outcome = 'Win' And fs.touchdowns > fs.interceptions

在 EAV 世界中看到你会得到

SELECT game_id FROM football_stats WHERE fs.team_fk = [Carolina] and stat_type = 'Outcome' and stat_value = 'Wins')
INTERSECT
SELECT game_ID FROM 
  (SELECT game_id, stat_value FROM football_stats WHERE fs.team_fk = [Carolina] and stat_type = 'Touchdown' ) tds,
  (SELECT game_id, stat_value FROM football_stats WHERE fs.team_fk = [Carolina] and stat_type = 'Interceptions') ints
WHERE
  tds.stat_value > ints.stat_value

所有所做的就是给你一个满足查询的 game_ids 列表,如果你想要其余的值,比如点无论赞成还是反对,这都是全新一轮的数据分析。

If you go with Astander here's the query you'd need for all the wins for Carolina when the scored more touchdowns then interceptions.

If you did it the right way, in columns, you'd see

SELECT * FROM Football_stats  fs
WHERE fs.team_fk = (something that resolves to Carolina)
fs.outcome = 'Win' And fs.touchdowns > fs.interceptions

in the EAV world you'd get

SELECT game_id FROM football_stats WHERE fs.team_fk = [Carolina] and stat_type = 'Outcome' and stat_value = 'Wins')
INTERSECT
SELECT game_ID FROM 
  (SELECT game_id, stat_value FROM football_stats WHERE fs.team_fk = [Carolina] and stat_type = 'Touchdown' ) tds,
  (SELECT game_id, stat_value FROM football_stats WHERE fs.team_fk = [Carolina] and stat_type = 'Interceptions') ints
WHERE
  tds.stat_value > ints.stat_value

And all that did was give you a list of game_ids that satisfy the query, if you want the rest of the values, like points for and against, it's whole new rounds through the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文