MySQL 数据库中的用户定义公式

发布于 2025-01-02 01:50:36 字数 494 浏览 0 评论 0原文

我有一个类似雪花模式的东西,它将电子表格形式的数据分解为进入一个表的数值,以及有关测量内容、主题、最初占据电子表格的哪一列、如何、何时、通过的信息who 等进入由外键连接的其他表的网络。

我有一个存储过程,它动态创建并运行带有一堆联接的查询,这些联接可以重建任何原始电子表格或模拟这些电子表格中任何用户选择的列组合的完整外部联接(联接已收集的数据)来自相同的测试对象)。

但是,输入电子表格通常包含公式。我不想将这些计算值视为静态数据,因为如果稍后在原始数据中进行更正,它们将不会传播,并且因为有时会在事后添加新公式

任何人都可以建议一种用于存储关联公式的通用设计模式吗如果用户要求的话,使用某种类型的数据并在输出上运行它们?我原本想在数据库层完成所有工作,但在看到 MySQL 的聚合函数和统计/数学函数有多么有限之后,我决定将公式传递到应用程序层(PHP)。

这是有关数据库设计的一般问题,所以我不知道多少细节有帮助。如果我的问题太模糊,请让我知道我应该包含哪些附加信息,我将相应地重新表述这个问题。谢谢。

I have something like a snowflake schema that decomposes data that I get in spreadsheet form into the numeric values that go into one table and information about what was measured, on what subjects, what column of the spreadsheet it originaly occupied, how, when, by whom, etc. into a network of other tables joined by foreign keys.

I have a stored procedure that dynamically creates and runs a query with a bunch of joins that can reconstitute any of the original spreadsheets or simulate a full outer join on any user-selected combination of columns from those spreadsheets (joined on the data having been collected from the same test subjects).

But, often the input spreadsheets contain formulas. I don't want to treat these calculated values as static data because then if corrections are later made in the raw data they will not propagate and because new formulas will sometimes be added after the fact

Can anybody suggest a generic design pattern for storing formulas associated with certain type of data and running them on the output if requested to do so by the user? I had originally wanted to do everything in the DB layer but after seeing how limited MySQL's aggregate functions and stats/math functions are, I'll settle for passing the formulas to the application layer (PHP).

This is general question about database design, so I don't know how much detail is helpful. If my quetion is too vague, please let me know what additional information I should inlude and I will reformulate this question accordingly. Thanks.

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

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

发布评论

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

评论(1

城歌 2025-01-09 01:50:36

由于数据库中的公式必须能够完全表示电子表格中可以表述的任何公式,因此我只需以电子表格中使用的相同格式存储公式即可。

将它们存储为 varchar 或 text 列,确保对值进行转义,或者存储为 varbinary 或 blob。只要您有办法将公式中的列名称映射回列值(我认为您已经说过可以做到),那么就一切就绪。

Since your formulas in the database have to be able to fully represent any formula that can be stated in a spreadsheet, I would simply store the formula in the same format that is used in the spreadsheet.

Store them as varchar or text columns, being sure to escape the values, or as varbinary or blob. As long as you have a way to map the column names in the formulas back to a column value, which I think you've stated you can do, then you're all set.

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