select ma.`majorName`, count(1) from `student` as stu
inner join `major` as ma
on ma.`majorId` = stu.`majorId`
group by `majorId`;
出现:
Error Code: 1052. Column 'majorId' in field list is ambiguous
要如何解决,感谢!!
ambiguous表示字段不明确。关联查询的两个表中都有majorId,但group by majorId
没有指定用哪个表中的majorId。使用 group by ma.mgajorId
或者 group by stu.majorId
mysql> select d.* from emp e right join dept d on e.deptno =d.deptno where e.empno is null;
+--------+------------+--------+
| DEPTNO | DNAME | LOC |
+--------+------------+--------+
| 40 | OPERATIONS | BOSTON |
+--------+------------+--------+
1 row in set (0.00 sec)