zoukankan      html  css  js  c++  java
  • 拼多多笔试题

    据说是拼多多的面试题,刚帮人解决的。。。
    题目一:

    今天帮人看的sql题目,要求见上图:

    ;with tb_info(CLASS,TEACHER,COURSE) as (
    
    	select '1','A','MATH'
    
    	UNION ALL
    
    	select '1','A','SPORTS'
    
    	UNION ALL
    
    	SELECT '1','B','LANGUAGE'
    
    	UNION ALL
    
    	SELECT '2','A','MATH'
    
    	UNION ALL
    
    	SELECT '3','B','MATH'
    
    	UNION ALL
    
    	SELECT '4','B','LANGUAGE'
    
    	UNION ALL
    
    	SELECT '5','A','SPORTS'
    
    	UNION ALL
    
    	SELECT '6','B','LANGUAGE'
    
    	UNION ALL
    
    	SELECT '6','C','MATH'
    
    )
    
    select t.teacher
    
           ,t.classNum
    
           ,count(distinct i.course) as courseNum
    
           from tb_info i join (
    
    							select teacher,count(*) as classNum from (
    
    												select  teacher,class 
    
    															from tb_info 
    
    																	group by teacher,class
    
    																			) temp 
    
    																			  group by teacher having count(class) > 3
    
    																			) t 
    
    							on i.teacher = t.teacher
    
    							group by t.teacher,t.classNum
    
    							
    
    

    题目二 求中位数:

    declare @freq_num int
    
    ;with tb_record(num,freq) as(
    
    	select 1,9
    
    	union ALL
    
    	select 2,2
    
    	union ALL
    
    	select 4,3
    
    	union ALL
    
    	select 6,1
    
    	union ALL
    
    	select 7,2
    
    	union ALL
    
    	select 9,1
    
    )
    
    , temp as (
    
    select num,freq
    
          ,(select sum(freq)  from tb_record sub where sub.num<=t.num) as ord_num 
    
          from tb_record t 
    
    )
    
    select  @freq_num = sum(freq) from tb_record
    
    declare @middle_digit int
    
    declare @sql_cmd varchar(max)
    
    set @middle_digit = @freq_num /2
    
    if @freq_num %2 =0
    
    BEGIN
    
    set @sql_cmd = '
    
    ;with tb_record(num,freq) as(
    
    	select 1,9
    
    	union ALL
    
    	select 2,2
    
    	union ALL
    
    	select 4,3
    
    	union ALL
    
    	select 6,1
    
    	union ALL
    
    	select 7,2
    
    	union ALL
    
    	select 9,1
    
    )
    
    , temp as (
    
    select num,freq
    
          ,(select sum(freq)  from tb_record sub where sub.num<=t.num) as ord_num 
    
          from tb_record t 
    
    )
    
    select sum(num)*1.0/2 from temp where temp.ord_num between '+cast(@middle_digit as varchar)+' and (select top 1 ord_num from temp t where t.ord_num>'+cast(@middle_digit as varchar)+')'
    
    print @sql_cmd
    
    exec(@sql_cmd)
    
    END
    
    
    ;with tb_record(num,freq) as(
    	select 1,9
    	union ALL
    	select 2,2
    	union ALL
    	select 4,3
    	union ALL
    	select 6,1
    	union ALL
    	select 7,2
    	union ALL
    	select 9,1
    )
    , temp as (
    select num,freq
          ,(select sum(freq)  from tb_record sub where sub.num<=t.num) as ord_num 
          from tb_record t 
    )
    select sum(num)*1.0/2 from temp 
                          where ord_num between (select max(ord_num)/2 from temp) 
                                        and (select min(ord_num) from temp where ord_num>(select max(ord_num)/2 from temp))
    
    
    如果有来生,一个人去远行,看不同的风景,感受生命的活力。。。
  • 相关阅读:
    java jdbc笔记整理
    Spring IOC (构造器注入)
    WEB-INF目录与META-INF目录的作用[转]
    [转]LL(1)文法判别之First集合、Follow集合、Select集合求法
    java读取TXT文件的方法 (转)
    Ubuntu 12.04下搭建Web服务器 (MySQL+PHP+Apache)(转)
    题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)
    error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCR...(转)
    汇编leal命令的灵活用法及理解
    C++之继承
  • 原文地址:https://www.cnblogs.com/Frank99/p/9354807.html
Copyright © 2011-2022 走看看