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

/* 
题目
 
如何产生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 
         
 
 
  
  
         
  
posted @   qanholas  阅读(7329)  评论(20编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
点击右上角即可分享
微信分享提示