sql面试题一道

已经知道原表
year salary
------------------ ---------------------
2000 1000
2001 2000
2002 3000
2003 4000
显示查询结果
year salary
------------------ ---------------------
2000 1000
2001 3000
2002 6000
2003 10000

即salary为以前年的工资的和

答案:

 1  use  northwind
 2  go
 3 
 4  select   *   from  orders
 5 
 6  select   *   from  orders  where  orderDate  between   ' 1996-07-04 '   and   ' 1996-07-20 '
 7 
 8  select   *   from  orders  where    dateadd ( day , 500 , orderDate) < getdate () 
 9  /* 创建表和数据库 */
10  create   database  test
11  go
12  use  test
13  go
14  create   table  Employee(
15      sId  int   identity  ( 1 , 1 primary   key ,
16       [ Year ]   datetime  ,
17      Salary  decimal
18  )
19  go
20  insert  Employee  values ( ' 2001 ' , 1000 )
21  insert  Employee  values ( ' 2002 ' , 2000 )
22  insert  Employee  values ( ' 2003 ' , 3000 )
23  insert  Employee  values ( ' 2004 ' , 5000 )
24  /* 查询语句 */
25  select   *   from  Employee
26  /* 答案 */
27  select  a. [ year ] , sum (b. [ salary ] from  Employee  as  a,Employee  as  b  where  b. [ year ] <= a. [ year ]   group   by  a. [ year ]
28 
29 

 

转载于:https://www.cnblogs.com/seerlin/archive/2008/11/10/1330477.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值