我正试图建立一个数据库视图,以显示未参加培训28天或更长时间的人。
CREATE VIEW InactiveMembers AS
SELECT Members.firstName,
Members.lastName,
Members.[FAN/FencerID],
Members.studentID,
Members.email,
Members.Sex,
Members.Handedness,
Members.MembershipClass,
hasPaid,
(
SELECT MAX(TrainingSessionDate)
FROM TrainingSessionAttendanceRoll
WHERE AttendedMember = "FAN/FencerID"
)
AS lastAttendedTrainingSession,
(
SELECT COUNT( * )
FROM TrainingSessionAttendanceRoll
WHERE AttendedMember = "FAN/FencerID"
)
AS TrainingSessionsAttended
FROM Members
WHERE (
SELECT julianday( (
SELECT MAX(TrainingSessionDate)
FROM TrainingSessionAttendanceRoll
)
) - julianday( (
SELECT MAX(TrainingSessionDate)
FROM TrainingSessionAttendanceRoll
WHERE AttendedMember = "FAN/FencerID"
)
)
) >= 28;
该视图应仅显示缺席28天或更长时间的人。
答案 0 :(得分:0)
没关系,找到了解决方法...
确保日期格式正确,因此不会返回NULL。