面试题(总结)

1.old表为老系统数据、new表中为新系统数据,需要根据相同的project、budgetcode去用old表中的projcost更新new表中的adjustment,使new表中extactcost+adjustment等于old表中的projcost(按照project、budgetcode),并最终更新extactcost等于projcost。

 

提示:1、old表的主键为project、budgetcode,new表中主键为project、budgetcode、line,当new表中出现多行是只更新第一行的         adjustment。
      2、请将详细sql语句用文本形式列出。

 

 

 

 

自己测试答案(SQL2008测试通过)

--===================================================================================
-- 说明:执行存储过程:exec updateOleToNewF
alter PROCEDURE [dbo].updateOleToNewF
AS
BEGIN
declare @project float
declare @budgetcode float
declare @line float

DECLARE   Name_cursor  CURSOR FOR
 
--取出要遍历的记录
select N.project,N.budgetcode,min(N.line) line
 from dbo.new N inner join dbo.old O
  on(N.project=O.project and N.budgetcode=O.budgetcode)
   group by N.project,N.budgetcode
   having COUNT(N.project+N.budgetcode)>=1
   order by N.project,N.budgetcode asc
  
OPEN Name_cursor
FETCH NEXT FROM Name_cursor INTO @project,@budgetcode,@line
WHILE @@FETCH_STATUS = 0
BEGIN 
declare @extactcost float
declare @adjustment float
declare @projcost float
select @extactcost=A.extactcost,@adjustment=A.adjustment,@projcost=B.projcost from dbo.new A inner join dbo.old B
on(A.project=B.project and A.budgetcode=B.budgetcode)
WHERE A.project=@project and A.budgetcode=@budgetcode and A.line=@line

 --更新差价,且只更新最小LINE的记录
 --update dbo.new set adjustment=@projcost-@extactcost where project=@project and budgetcode=@budgetcode and line=@line
 --更新总价,也只更新最小LINE的总价
 update dbo.new set extactcost=@projcost where project=@project and budgetcode=@budgetcode and line=@line
 FETCH NEXT FROM Name_cursor INTO @project,@budgetcode,@line
END
CLOSE Name_cursor
DEALLOCATE Name_cursor
END


--以下SQL用于查询结果,进行数据比较
select a.*,b.*
from old a,new b
 where a.project =b.project and a.budgetcode=b.budgetcode

 

 

2.不用C/C++中的STRPCY函数并能实现类似的功能。

我用。NET测试通过

public void copyStr(char[] dest, char[] sourse)
        {
            for (int i = 0; i < sourse.Length; i++)
            {
                dest[i] = sourse[i];
                Response.Write(dest[i]);
            }
        }

感觉太简单了吧。。不知道对否?

3.     给定一个文件,内部存储着32亿个32位的整数,找到其中存在重复的整数(并计算这个文件大概大小)(并给出思路)

这个真不会!!

你可能感兴趣的:(JOIN,sql,面试,测试,float)