今天去面试了一家公司,有一个题目比较有趣

2010-11-26 07:27

今天去面试了一家公司,有一个题目比较有趣

by qanholas

at 2010-11-25 23:27:00

original http://www.cnblogs.com/qanholas/archive/2010/11/25/1888248.html

/* 
题目
 
如何产生1万个编号,插入到表 T(col varchar(20))中,并且不能重复,编号只能从26个小写字母中取 . 
*/ 
 
--1.当时的写法 
select  'a' as col 
into    #t 
union  
select  'b' union 
select  'c' union 
select  'd' union 
select  'e' union 
select  'f' union 
select  'g' union 
select  'h' union 
select  'i' union 
select  'j' union 
select  'k' union 
select  'l' union 
select  'm' union 
select  'n' union 
select  'o' union 
select  'p' union 
select  'q' union 
select  'r' union 
select  's' union 
select  't' union 
select  'u' union 
select  'v' union 
select  'w' union 
select  'x' union 
select  'y' union 
select  'z'   
 
 
 
 
insert into T 
select    top 10000  a.col+b.col+c.col      from  #t  a,#t b ,#t c 
  
drop table #t  
 
 
  
 
 

-------------------------------------------------------------- 
  
--2.看到varchar(20), 想到newid(),再做一些字符串处理 
 
insert into T 
select top 10000 
        replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(lower(left(replace(newid(), 
                                                              '-', ''), 20)), 
                                                              '0', 'a'), 1
                                                              'b'), 2, 'c'), 3
                                                              'd'), 4, 'e'), 5
                                                'f'), 6, 'g'), 7, 'h'), 8, 'i'), 
                9, 'j') as col 
from    sys.all_columns , 
        sys.all_objects 
         
 
 
  
  
         
  

作者: qanholas 发表于 2010-11-25 23:27 原文链接

评论: 13 查看评论 发表评论


最新新闻:
· 微博与SNS谁称雄(2010-11-26 15:48)
· LBS将成为移动信息平台发展的关键转折点(2010-11-26 15:46)
· 陈年:VANCL能比优衣库做得大 1000亿才是梦想(2010-11-26 15:36)
· CSDN高管:腾讯曾高薪挖对手公司人才(2010-11-26 15:33)
· 360就十万水军发布声明:有人意图抹黑360(2010-11-26 15:18)

编辑推荐:网站开发人员应该知道的61件事

网站导航:博客园首页  我的园子  新闻  闪存  小组  博问  知识库