如何在SQL环境中创建以下数据结构

发布于 2025-01-25 20:33:38 字数 708 浏览 2 评论 0原文

我有一个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 技术交流群。

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

发布评论

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

评论(1

我要还你自由 2025-02-01 20:33:38

在关系数据库中,您通常会有这些表

  • SENINARSANDTRAINing,该表存储st_name
  • siminarsandtraining_attendance_attendance ,它存储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 stores st_name
  • SeminarsAndTraining_attendance, which stores the date of each attendance, and the ID of the SeminarsAndTraining it belong to.
  • SeminarsAndTraining_attendance_present, which stores each ID from the present field, and the ID of the SeminarsAndTraining_attendance it belong too.
  • SeminarsAndTraining_attendance_absent, which stores each ID from the abssent field, and the ID of the SeminarsAndTraining_attendance it belong too.

You could probably merge the last two tables, and include a present_or_absent value for each.

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