当前位置:首页 > 技术杂谈 > 正文

mysql中给查询出的结果集添加自增序号

2024-03-31 技术杂谈

select (@i:[email protected] 1) i,emp.* from emp,(select @i:=0) it

 

按部门分组并按薪资总和从大到小排序求薪资总和第二高的部门名称和薪资总和:select c.ename,c.s from (select (@i:[email protected] 1) i,e.*  from (SELECT ename,SUM(sal) s FROM emp GROUP BY deptno ORDER BY s desc) e,(select @i:=0) it) c where c.i=2

 

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/a/22978.html