为静态 ORM 展开 SQLite 数据透视查询,问题是它需要空值来表示缺失值。
table student
student_id | name
1 "Fred"
2 "Tim"
PK(`student_id`)
table grade
student_id | data_id | grade
1 1 5.0
1 2 5.0
2 2 5.0
PK(`student_id`,`data_id`),
FK(student.studentid)
FK(data.data_id)
table data
data_id | description
1 "summer"
2 "autumn"
PK(`data_id`)
我需要结果包含一个空行,以便静态 ORM 正确制表。在我看来,这应该意味着左加入:
SELECT * FROM student
join grade using (student_id)
LEFT OUTER JOIN data
ON grade.data_id = data.data_id
由于 Tim 暑期考试缺席,student_id 没有一行 | 表等级中的 data_id PK_pair(2,1)。
查询当前返回:
sID | name | dID | grade | description
"1" "Fred" "1" "5.0" "summer"
"1" "Fred" "2" "5.0" "autumn"
"2" "Tim" "2" "5.0" "autumn"
结果中缺少此行:
sID | name | dID | grade | description
"2" "Tim" "1" null "summer"