在数据库中计数教师
我认为我有正确的想法来解决这个功能,但我不知道为什么当我尝试测试它时出现此错误。任何人都可以帮我解决这个问题吗?在数据库中计数教师
cur.execute(Q) sqlite3.OperationalError:邻近 “具有”:语法错误
课程表:ID,场,章节,名称 位置表:ID,
室所需的输出:
>>> courses_how_many_instructors(db) [('HLTC16H3F', 2), ('MATA29H3F', 2), ('MATA32H3F', 3), ('MATA67H3F', 2), \
('MGAB01H3F', 3), ('MGAB03H3F', 2), ('MGAD65H3F', 2), ('BIOA01H3F', 3), \
('POLB80H3F', 2), ('STAB22H3F', 2), ('VPMA93H3F', 2), ('CHMA10H3F', 2), \
('CHMB16H3F', 2), ('CSCA08H3F', 2), ('CSCA67H3F', 2)]
def courses_how_many_instructors(db):
'''Return the course number and the number of instructors for courses with
more than one instructor. Note that this means the ID must be
the same for each instructor.'''
query = '''SELECT Course, Name FROM Courses WHERE NAME>1 GROUP BY HAVING COUNT(Name)'''
return run_query(db, query)
回答:
你需要将你的结果由course
柱:
SELECT course, COUNT(DISTINCT name) AS num_instructors FROM courses
GROUP BY name
HAVING COUNT(DISTINCT name) > 1
以上是 在数据库中计数教师 的全部内容, 来源链接: utcz.com/qa/258166.html