SQL 对列中的总值求和时查询未返回预期值

SQL query not returning expected values when summing total values in a column

我有这个架构:

对于这个模式,我需要“提供 SQL 查询,该查询将为每个学生生成名字、姓氏、开始年份和学分总数。您不应该考虑具有0 年级,因为这些对应于失败的课程

到目前为止我有这个:

def q4(self):
    query = '''
    select s.firstName, s.lastName, s.yearStarted,count(*)
    from students s, grades g
    where s.sid = g.sid
    and g.grade >0
    group by s.firstName, s.lastName, s.yearStarted
    '''
    self.cur.execute(query)
    all_rows = self.cur.fetchall()
    return all_rows

和returns这些值:

[('Anne', 'Brown', 2020, 1), ('Jack', 'Thomson', 2018, 3), ('Jacob', 'McKarthy', 2020, 2), ('Jamal', 'Jones', 2019, 3), ('Jane', 'Doe', 2017, 2), ('John', 'Doe', 2017, 3), ('Tim', 'Burton', 2018, 3), ('Tina', 'Gilligan', 2019, 3)]

但显然这些都是错误的,当我上传到 gradescope 时,它​​给了我这些位于附加图像中的错误

知道我做错了什么吗?

我找到答案了。感谢@ChristianSloper 对我的帮助

def q4(self):
    query = '''
    select s.firstName, s.lastName, s.yearStarted,count(*)  as cnt
    from students s, grades g
    where s.sid = g.sid
    and g.grade >0
    group by s.sid, s.yearStarted
    order by s.yearStarted
    desc
     
    '''
    self.cur.execute(query)
    all_rows = self.cur.fetchall()
    return all_rows