题目如下:
通过表1的信息 ,用SQL语句实现表2的结果!
year salary(表1)
2000 1000
2001 2000
2002 3000
2003 4000
2004 5000 year salary(表2)
2000 1000
2001 3000
2002 6000
2003 10000
2004 15000
通过表1的信息 ,用SQL语句实现表2的结果!
year salary(表1)
2000 1000
2001 2000
2002 3000
2003 4000
2004 5000 year salary(表2)
2000 1000
2001 3000
2002 6000
2003 10000
2004 15000
解决方案 »
- 请教一个函数如何写?分店铺判断并减少库存及店铺库存。
- sql存储过程语句怎么改成asp里面的sql语句
- 磁盘活动量是干什么的?
- SQL是否有replace()字符函数?
- 一次性修改表的多个字符的类型
- 安装MSDE(sp3版)成功后不能运行,日志中有提示错误: 15457,但我不知道怎么处理
- 高手请进:SQL Server下常用的3个数据操纵方法,用Access2000作桌面数据库时不知怎样实现?在线等待...
- 我想在一个结果集中返回一个数据库中的所有用户表和它是否有标志字段,如何做呢?
- 如何知道自己使用的ADO版本?
- 如何把SQL2000的记录写入文本文件(用ASP)实现
- SQL 2000与SQL2008性能有多少大提升,还有32位系统与64位系统的性能问题
- 备份的physical_device_name 含义
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([year] int,[salary] int)
insert [TB]
select 2000,1000 union all
select 2001,2000 union all
select 2002,3000 union all
select 2003,4000 union all
select 2004,5000select [year],[salary]=(select sum([salary]) from TB where [year]<=t.[year]) from [TB] t/*
year salary
----------- -----------
2000 1000
2001 3000
2002 6000
2003 10000
2004 15000(5 行受影响)*/drop table TB
,(select sum(salary) from 表1 A where A.year<=year) as 'salary'
from 表1
,(select sum(salary) from 表1 where year<=A.year) as 'salary'
from 表1 A
from tb a
join tb b on a.[year]>=b.[year]
group by a.[year]/**
year salary
----------- -----------
2000 1000
2001 3000
2002 6000
2003 10000
2004 15000(所影响的行数为 5 行)
**/
select a.[year],sum(b.salary) as salary
from 表1 a
join 表2 b on a.[year]>=b.[year]
group by a.[year]
[salary]=(select sum([salary]) from TB where [year]<=t.[year])
from [TB] t
[year],
[salary]=(select sum([salary]) from 表 A where A.[year]<=B.[year])
from
表 B
create table [TB]([year] int,[salary] int)
insert [TB]
select 2000,1000 union all
select 2001,2000 union all
select 2002,3000 union all
select 2003,4000 union all
select 2004,5000select [year],
(select sum([salary]) from [TB] where [year]<=t.[year]) [salary]
from [TB] Tyear salary
----------- -----------
2000 1000
2001 3000
2002 6000
2003 10000
2004 15000(5 行受影响)
create table tbb(y int,s int)
insert into tbb
select 2000,1000 union all
select 2001,2000 union all
select 2002,3000 union all
select 2003,4000 union all
select 2004,5000select aa.y,sums=(select SUM(bb.s) from tbb as bb where bb.y<=aa.y)
from tbb as aadrop table tbb
create table tb(year datetime,salary int)
insert tb
select '2000',1000 union all
select '2001',2000 union all
select '2002',3000 union all
select '2003',4000 union all
select '2004',5000
select convert(char(4),year,112) as year,(select sum(salary) from tb where year<=a.year) as salary
from tb a