简体   繁体   English

如何修复以下MYSQL语句?

[英]How do i fix the following MYSQL statement?

List the number of Judges graduated from each law school. 列出每所法学院毕业的法官人数。 The tables are Presidents , Judges , and Appoints . 这些表是PresidentsJudgesAppoints Judges has columns JName , DateOfBirth , LawSchool . Judges拥有JNameDateOfBirthLawSchool列。 I have tried the following statement and am running into an error I am not sure I understand completely: 我尝试了以下语句,但遇到错误,不确定我是否完全理解:

SELECT jname, COUNT(jname)
FROM Judges J1, Judges J2
WHERE J1.LawSchool = J2.LawSchool AND J1.Jname != J2.Jname;

The error is: ERROR 1052: Column 'jname' in field list is ambiguous . 错误是: ERROR 1052: Column 'jname' in field list is ambiguous

The field jname exist in more then one table that you are selecting data from (Judges J1 & Judges J2). 字段jname存在于一个以上的表中(您要从中选择数据)(法官J1和法官J2)。 You have to specify which table you want this data from. 您必须指定要从哪个表中获取此数据。 But, according to your task, I think the right way to do this is: 但是,根据您的任务,我认为正确的方法是:

SELECT LawSchool, COUNT(*)
FROM Judges
Group By LawSchool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM