帮助 mysql 查询或数据库设计来帮助我实现这一目标
我一直是该网站的长期读者,但以前从未发过帖子,希望这里有人能提供帮助。我正在开发一个多用户 Web 应用程序,该应用程序允许用户将潜在客户信息捕获到我们的数据库中。用户将在应用程序内获得默认字段,例如分组为数据组的姓名和电子邮件。
但是,我希望允许用户创建任意数量的自定义字段,并允许他们选择这些自定义字段属于哪个数据组。我正在努力找出实现这一目标的最佳方法。
我的数据中目前有 3 个表,如下所示:
datagroups
group_id group_name order
1 test group 1 2
2 test group 2 1
datafields
field_id field_name group
1 field 1 2
2 field 2 1
3 field 3 2
customdatafields
custom_field_id field_name group
1 custom 1 1
2 custom 2 2
我真的很困惑如何在这 3 个表中创建查询,以便我可以在显示后生成视图:
test group 2
- field 1
- field 3
- custom 2
test group 1
- field 2
- custom 1
我需要记住的一件事是我可能允许用户创建自定义数据组,这也需要考虑在内。
对此的任何意见将不胜感激。
谢谢
I have been a long time reader of site but havenever posted before and am hoping someone here can help. I am working on a multi-user web application which allows users to capture prospect information into our database. The users will be given default fields inside the app, such as name and email which are grouped into data groups.
However i want to allow the users to create as many custom fields as they wish and also allow them to choose which data group these custom fields belong in group. I am struggling to figure out the best way to achieve this.
I have currently have 3 tables in my data which are as follows:
datagroups
group_id group_name order
1 test group 1 2
2 test group 2 1
datafields
field_id field_name group
1 field 1 2
2 field 2 1
3 field 3 2
customdatafields
custom_field_id field_name group
1 custom 1 1
2 custom 2 2
I am really puzzled on how I would create a query across the 3 tables so that I can produce a view following display:
test group 2
- field 1
- field 3
- custom 2
test group 1
- field 2
- custom 1
One thing I need to keep in mind is that I may allow the users to create custom data groups also that that needs to be factored into this.
Any input on this would be much appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您所描述的输出不是表格形式的...所以不是直接从 sql 语句中得到的输出。
但是,您应该能够通过使用 UNION 来获取列表,可能是这样的:
well, your described output is not tabular... so not directly what you will get form a sql statement.
however, you should be able to get listings by using UNION maybe something like this:
您刚刚让每个临时用户成为您的数据库设计师。
这听起来是个好主意吗?
任何应该表格中的行最终都会成为单列中的逗号分隔字符串。数据迟早会变成这样。
人们为什么要这么做?因为普通人不知道如何设计数据库。他们会做最权宜的事情,就是现在把数据随便放,然后再想办法处理。
哎呀,SO 上的大多数程序员都不知道如何设计数据库。只需阅读一周左右的[数据库]问题即可。 (包括这个版本的十几个变体。)
您不想为此使用 MySQL 或任何 SQL dbms。如果您一开始就不能做好建模工作,那么 SQL 数据库管理系统只会让您提前死去。
You've just made every casual user your database designer.
Does that sound like a good idea?
Anything that should be a row in a table will end up being a comma separated string in a single column. Data will end up looking like this, sooner or later.
Why would people do that? Because ordinary people don't know how to design databases. They'll do the most expedient thing, which is just put data in any which way now, and figure out how to deal with it later.
Heck, most of the programmers on SO don't know how to design databases. Just read [database] questions for a week or so. (Including a dozen variants of this very one.)
You do not want to use MySQL or any SQL dbms for this. If you can't do a proper job of modeling to start with, a SQL dbms will just make you die before your time.