我有這個架構:Students(sid:int,名字:str,姓氏:str,年份開始:int)Majors(sid: int, Major: str)注意:一名學生可能有多個專業。Grades(sid:int,cid:int,學分:int,等級:int)注:sid,cid =外鍵,等級:A = 4,B = 3,C = 2,D = 1,F = 0。Courses(cid:int,number:int,教授:str,專業:str,年份:int,學期:str)注意:cid在各個學期中是唯一的。學期為夏季、秋季或春季。如果兩個課程具有相同的編號 + 專業,則它們是相同的通過這個模式,我需要“提供 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并返回這些值:[('安妮', '布朗', 2020, 1), ('杰克', '湯姆森', 2018, 3), ('雅各布', '麥卡錫', 2020, 2), ('賈馬爾', '瓊斯', 2019, 3), ('簡', 'Doe', 2017, 2), ('約翰', 'Doe', 2017, 3), ('蒂姆', '伯頓', 2018, 3), ( “蒂娜”,“吉利根”,2019,3)]但顯然這些是錯誤的,當我上傳到 Gradescope 時,它給了我這些位于附圖中的錯誤有什么想法我做錯了嗎?
1 回答

躍然一笑
TA貢獻1826條經驗 獲得超6個贊
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
添加回答
舉報
0/150
提交
取消