如何在SQL环境中创建以下数据结构
我有一个Firestore数据库,需要将其转换为SQL。我的SENINARSANDTRAINing
文档看起来像这样:
{
"st_name": "SOL Level 1",
"attendance": [
{"date": "01/29/2021", "present": ["9103", "1282"], "absent": ["8127"]},
{"date": "01/29/2021", "present": ["1203", "1224"], "absent": ["0927"]}
]
}
我有这些SENINARSANDTRAINing
文档中的多个文档。 出勤
数组中的对象包含出勤的日期,学生的ID存储在Present
和缺少
array中。
问题1 我知道您不能在SQL中有数组,那么最好的方法是什么?
"attendance": [
{"date": "01/29/2021", "present": ["9103", "1282"], "absent": ["8127"]},
{"date": "01/29/2021", "present": ["1203", "1224"], "absent": ["0927"]}
]
I have a FireStore database and I need to convert it to SQL. My SeminarsAndTraining
document looks like this:
{
"st_name": "SOL Level 1",
"attendance": [
{"date": "01/29/2021", "present": ["9103", "1282"], "absent": ["8127"]},
{"date": "01/29/2021", "present": ["1203", "1224"], "absent": ["0927"]}
]
}
I have multiple of these SeminarsAndTraining
documents inside a collection. The object inside the attendance
array contains the date for the attendance and the students' id is stored in the present
and absent
array.
Problem 1
I know you can't have arrays in SQL, so what is the best approach to this?.
"attendance": [
{"date": "01/29/2021", "present": ["9103", "1282"], "absent": ["8127"]},
{"date": "01/29/2021", "present": ["1203", "1224"], "absent": ["0927"]}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在关系数据库中,您通常会有这些表
SENINARSANDTRAINing
,该表存储st_name
date
每次出席的情况以及它属于seminarsandtraining
的ID。siminarsandtraining_attendance_present
,从呈现
字段中存储每个ID,以及siminarsandtraining_attendance
的ID也属于。sininarsandtraining_attendance_absent
,从abssent
字段中存储每个ID,以及siminarsandtraining_attendance
的ID也属于。您可能可以合并最后两个表,并在每个表中包含
rastry_or_absent
值。In a relational database you'll typically have these tables
SeminarsAndTraining
, which storesst_name
SeminarsAndTraining_attendance
, which stores thedate
of each attendance, and the ID of theSeminarsAndTraining
it belong to.SeminarsAndTraining_attendance_present
, which stores each ID from thepresent
field, and the ID of theSeminarsAndTraining_attendance
it belong too.SeminarsAndTraining_attendance_absent
, which stores each ID from theabssent
field, and the ID of theSeminarsAndTraining_attendance
it belong too.You could probably merge the last two tables, and include a
present_or_absent
value for each.