zoukankan      html  css  js  c++  java
  • 今天去面试了一家公司,有一个题目比较有趣

    /* 
    题目
     
    如何产生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 
             
     
     
      
      
             
      
  • 相关阅读:
    ZOJ2402 Lenny's Lucky Lotto List 简单DP
    HDU1024 最大M子段和问题 (单调队列优化)
    HDU2048 HDU2049 组合数系列 错排
    HDU1081 最大字段和 压缩数组(单调队列优化)
    HDU1166 数状数组
    HDU1085 多重背包
    HDU3062
    递归 递推 规律
    【机器学习PAI实战】—— 玩转人工智能之美食推荐
    阿里开源自用 OpenJDK 版本,Java 社区迎来中国力量
  • 原文地址:https://www.cnblogs.com/qanholas/p/1888248.html
Copyright © 2011-2022 走看看