参考查询链接:https://www.cnblogs.com/shengs/p/5954818.html
- select * from (select ename, job, hiredate, e.sal, e.deptno
- from emp e,
- (select deptno, max(sal) sal from emp group by deptno) t
- where e.deptno = t.deptno
- and e.sal = t.sal)
- order by deptno;
- select * from (select ename 姓名, job 职业, hiredate 入职日期, e.sal 工资, e.deptno 部门
- from emp e,
- (select deptno, max(sal) sal from emp group by deptno) t
- where e.deptno = t.deptno
- and e.sal = t.sal)
- order by 部门;
select * from (两表联查 xx ,(select 公司ID,max(时间)from 表) t where xx.时间=t.时间 and xx.公司ID=t.公司ID)
这个方法是把其中一个表分组过滤出最新时间和主键cust