zoukankan      html  css  js  c++  java
  • day 16面试题

    查询出没门课程都大于80的学生的姓名


    select name from table group by name having MIN(fenshu)>80

    编号自增:identity(1,1)

    删除除了编号以后,其他信息相同的信息
    自动编号 学号 姓名 课程名称 分数
    1 200 张三 数学 89
    2 200 张三 数学 98
    3 201 李四 数学 65

    create table sdata.dbo.test(
    id varchar(20)
    ,xh varchar(20)
    ,name varchar(20)
    ,ckname varchar(20)
    ,fs varchar(20)
    )

    insert into sdata.dbo.test
    values(
    '1', '200', '张三', '数学',89
    )
    insert into sdata.dbo.test
    values(
    '6' , '200','张三', '数学',98
    )

    insert into sdata.dbo.test
    values(
    '3', '201','李四','数学',86
    )
    insert into sdata.dbo.test
    values(
    '5', '202','王五','数学', 86
    )

    select * from sdata.dbo.test

    用row_number 排序找出大于1的
    select ID
    --into sdata.dbo.delete_id
    from (
    select *,
    row_number()over(partition by xh,name,ckname,fs order by id asc) as paixu
    from sdata.dbo.test) a
    where paixu> 1

    select * from sdata.dbo.delete_id

    --删除大于1的数据
    delete from sdata.dbo.test
    where exists
    (select 1 from sdata.dbo.delete_id
    where sdata.dbo.delete_id.id = sdata.dbo.test.id
    )

    abcd四种 求不同的结果
    create table sdata.dbo.name_play(
    name varchar(20)
    )
    insert into sdata.dbo.name_play values('a')
    insert into sdata.dbo.name_play values('b')
    insert into sdata.dbo.name_play values('c')
    insert into sdata.dbo.name_play values('d')

    select distinct a.name,b.name from sdata.dbo.name_play a
    left join sdata.dbo.name_play b
    on a.name<>b.name

    不分主客场的话

    select distinct a.name,b.name from sdata.dbo.name_play a
    inner join sdata.dbo.name_play b
    on a.name<b.name


    怎么把一个表竖表转化成横表 用转至算
    create table sdata.dbo.zhuanzhi(
    year varchar(20)
    ,month varchar(20)
    ,amount varchar(20)
    )

    insert into sdata.dbo.zhuanzhi values(
    '1992','4','2.4'
    )
    select * from sdata.dbo.zhuanzhi

    select YEAR
    ,MAX(mon_1) mon_1
    ,MAX(mon_2) mon_2
    ,MAX(mon_3) mon_3
    ,MAX(mon_4) mon_4
    into sdata.dbo.heng
    from(
    select YEAR
    ,case when month = 1 then amount else null end mon_1
    ,case when month = 2 then amount else null end mon_2
    ,case when month = 3 then amount else null end mon_3
    ,case when month = 4 then amount else null end mon_4
    from sdata.dbo.zhuanzhi) a
    group by YEAR

    --横表转纵表

    select YEAR
    ,mon_1 as amount
    ,'1' as month
    from sdata.dbo.heng
    union all
    select YEAR
    ,mon_2 as amount
    ,'2' as month
    from sdata.dbo.heng
    union all
    select YEAR
    ,mon_3 as amount
    ,'3' as month
    from sdata.dbo.heng
    union all
    select YEAR
    ,mon_4 as amount
    ,'4' as month
    from sdata.dbo.heng

  • 相关阅读:
    mysql命令汇总
    python中魔术方法和属性汇总
    python关于import的汇总
    linux命令汇总
    python之高并发问题汇总
    python中路径查找汇总
    python之进程,线程,协程,进程间通信,锁汇总
    python之迭代器,生成器,递归等归纳
    python 之网络编程汇总
    【SpringFramework】Spring JdbcTemplate
  • 原文地址:https://www.cnblogs.com/simly/p/9513864.html
Copyright © 2011-2022 走看看