SQL-59 按照salary的累计和running_total,其中running_total为前两个员工的salary累计和,其他以此类推。
题目描述
CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL,
`salary` int(11) NOT NULL,
`from_date` date NOT NULL,
`to_date` date NOT NULL,
PRIMARY KEY (`emp_no`,`from_date`));
输出格式:
| emp_no | salary | running_total |
|---|---|---|
| 10001 | 88958 | 88958 |
| 10002 | 72527 | 161485 |
| 10003 | 43311 | 204796 |
| 10004 | 74057 | 278853 |
| 10005 | 94692 | 373545 |
| 10006 | 43311 | 416856 |
| 10007 | 88070 | 504926 |
| 10009 | 95409 | 600335 |
| 10010 | 94409 | 694744 |
| 10011 | 25828 | 720572 |
select a.emp_no,a.salary,sum(b.salary)as running_total
from salaries as a,salaries as b
where b.emp_no<=a.emp_no
and a.to_date='9999-01-01'
and b.to_date='9999-01-01'
group by a.emp_no
order by a.emp_no
SQL-59 按照salary的累计和running_total,其中running_total为前两个员工的salary累计和,其他以此类推。的更多相关文章
- [SQL]LeetCode185. 部门工资前三高的员工 | Department Top Three Salaries
SQL 架构 Create table If Not Exists Employee (Id ), Salary int, DepartmentId int) Create table If Not ...
- Leetcode的SQL题解:185. 部门工资前三高的员工
题目 查询部门工资前三高的员工. 我用的数据库是oracle. 下面是数据表的信息. Employee表数据: | ID | NAME | Salary | DepartmentId | | -- | ...
- sql查询:部门工资前三高的员工和部门工资最高的员工
创建表:Create table If Not Exists Employee (Id int, Name varchar(255), Salary int, DepartmentId int);Cr ...
- SQL Server中灾难时备份结尾日志(Tail of log)的两种方法
转自:http://www.cnblogs.com/CareySon/archive/2012/02/23/2365006.html SQL Server中灾难时备份结尾日志(Tail of log) ...
- SQL SERVER 下:1、递归查询父分类下的各个子分类。 2、查询每个商品分类中最贵的前两个商品SQL
1.递归查询父分类下的各个子分类.表设计: SQL: --CTE 语句(适用于MSSQL2005以后版本) with cte_testNavi(Id,Name,Pid ) as ( --这是查询语句 ...
- sql server编写脚本求解第1天1分钱之后每天两倍持续一个月的等比数列问题
一.问题 问题1 场景:如果你未来的丈母娘要求你,第1天给她1分钱,第2天给2分钱,第3天给4分钱,以此类推,每天给前一天的2倍,给1个月(按30天)算就行.问:第30天给多少钱,总共给多少钱? 问题 ...
- SQL查询每个部门工资前三名的员工信息
--通用sql select deptno, ename, sal from emp e1 where ( ) from emp e2 where e2.deptno=e1.deptno and e2 ...
- sql优化------查询整个表按照某个字段排序后的前几条
后续补充
- 用sql的avg(score)求完平均值后,保存两位小数的方法(用于查询或视图)
查jx_score表的平均值,以哪次考试(testid)和科目分组(courseid) select testid, courseid, round(avg(`jx_score`.`score`),2 ...
随机推荐
- gulp自动化构建工具的使用
gulp自动化构建工具: 把前端开发常见的处理(“搬砖”)程序,通过一个工具模块管理起来,只需配置一次,达到自动处理目的,简化开发,提高效率!! 安装: 1.全局安装(全局安装一个gulp命令) A. ...
- 人脸识别-arcface损失函数
参考博客: L-margin softmax loss:https://blog.csdn.net/u014380165/article/details/76864572 A-softmax loss ...
- 关于隐式创建vue实例实现简化弹出框组件显示步骤
我们在使用vue写alert组件的时候,经常是定义了一个alert.vue,然后引入alert.vue,然后配置参数等等,非常繁琐,那有没有一种方式可以像window.alert("内容&q ...
- 开发者的自测利器-Hprof命令(寻找cpu热点)
测试代码: public class HProfTest { public void slowMethod() { try { Thread.sleep(1000); } catch (Excepti ...
- Django的admin相关
自定义admin展示的内容 根据之前已经创建好了的models from django.db import models class Person(models.Model): name = mode ...
- Vue 组件异步加载(懒加载)
一.vue的编译模式 (1)路由配置信息 //eg1: const MSite = resolve => require.ensure([], () =>resolve(require([ ...
- laravel框架的注入
如果项目太大,最好采用注入的方式 首先在 根目录/app/ 下创建个service文件夹来 在控制器层可以调用 调用方法
- 《Coderxiaoban团队》第二次作业:团队项目选题报告
<Coderxiaoban团队>第二次作业:团队项目选题报告 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 实验六 团队作业2:团队项目选题 团队名称 Co ...
- JUC原子类--01
JUC原子操作类分为四种类型 1. 基本类型: AtomicInteger, AtomicLong, AtomicBoolean ;2. 数组类型: AtomicIntegerArray, Atomi ...
- 超简DbHelper
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Dynamic; n ...