2020-05-18
阅读量:
1125
MySQL什么情况下必须写别名?
1.子查询
(1)from子查询
select t.grade,count(t.empno) 员工数 from (select * from salgrade join emp on emp.sal between losal and hisal) t group by grade;
(2)在连接的表中查询一列或几列数据时,需要带上相应的表名
select t1.ename,t2.dname,t2.部门人数 from(select ename,deptno from emp where job='manager') t1 join (select dept.deptno,dept.dname,count(emp.empno) 部门人数 from dept join emp on dept.deptno=emp.deptno group by dept.deptno) t2 on t1.deptno=t2.deptno;
2.自连接
select *
from emp as 领导表
join emp as 员工表 on 领导表.empno=员工表.mgr
join dept on 员工表.deptno=dept.deptno
where 员工表.hiredate<领导表.hiredate;#老师思路
37.2877
3
2
关注作者
收藏
评论(0)
发表评论
暂无数据
推荐帖子
0条评论
0条评论
1条评论