为什么我的SQLite数据库视图没有显示任何行?

时间:2019-07-18 20:26:51

标签: sql sqlite

我正试图建立一个数据库视图,以显示未参加培训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天或更长时间的人。

1 个答案:

答案 0 :(得分:0)

没关系,找到了解决方法...

确保日期格式正确,因此不会返回NULL。