用一条语句完成!
1)        一个表中有DepartId和Salary两个字段,从该表中查询出各个部门薪水排第二的记录(表名字为UserInfo)
部门id  工资
1       1500
1       1000
2       800
2       1200
3       600
3       400
2)        已知原表(t_salary)
   Year  Salary
2000        1000
2001        2000
2002        3000
2003        4000
2004        5000
要求查询返回如下的结果
Year Salary
2000        1000
2001        3000
2002        6000
2003        10000
2004        150003)两表关联,删除主表中在副表中没有的信息
stuinfo
stuid    stuname
1         a
2         b
3         cinfo
examNo       stuid     english
100            1          78
101            2          344)有两个表A和B,均有id 和age 两个字段,如果B的id在A中也有, 就把B的age换为A中对应的age

解决方案 »

  1.   

    1
    select DepartId,Salary
    from
    (
    select a.*,dense_rank() over(partition by DepartId order by salary desc ) rn 
    from userinfo a
    )
    where rn=2
      

  2.   

    2
    select Year,sum(salary) over(order by year) salary
    from t_salary
      

  3.   

    3
    delete stuinfo a
    where no exists
    (
    select 1
    from info
    where a.stuid=b.stuid
    )
      

  4.   

    支持何波
    第三道题的info表忘了赋列别名b,或者将下面的a.stuid=b.stuid改成a.stuid=stuid也行第四道
    update b  set age=(select age from a where id=b.id)
    where exists(select 1 from a where id=b.id)
      

  5.   

    NND,同一人不能连续回复三次,第四题就回复不上了
      

  6.   

    第4题也可以用merge
    merge into b
    using a
    on (a.id=b.id)
    when matched then
    update 
    set age=a.age