zoukankan      html  css  js  c++  java
  • Sql 常用面试题

    可以在"易百教程"学习sql 语句:http://www.yiibai.com/

    1. 用一条SQL 语句 查询出每门大于80 分的学生姓名

    姓名     课程      分数 
    张三     语文       81
    张三     数学       75
    李四     语文       76
    李四     数学       90
    王五     语文       81
    王五     数学       100
    王五     英语       90

    select 姓名 from student group by  姓名 having count(课程)>2 and min(分数)>80

    2.删除除了自动编号不同, 其他都相同的学生冗余信息

    自动编号       学号        姓名    课程编号     课程名称     分数
    1             2005001     张三      0001         数学         69
    2             2005002     李四      0001         数学         89
    3             2005001     张三      0001         数学         69

    delete tablename where 自动编号 not in(select min( 自动编号) from tablename group by 学号, 姓名, 课程编号, 课程名称, 分数)

    5. 面试题:怎么把这样一个表儿
    year   month amount
    1991   1     1.1
    1991   2     1.2
    1991   3     1.3
    1991   4     1.4
    1992   1     2.1
    1992   2     2.2
    1992   3     2.3
    1992   4     2.4
    查成这样一个结果
    year m1   m2   m3   m4
    1991 1.1 1.2 1.3 1.4
    1992 2.1 2.2 2.3 2.4 

    select year, 
    (select amount from   aaa m where month=1   and m.year=aaa.year) as m1,
    (select amount from   aaa m where month=2   and m.year=aaa.year) as m2,
    (select amount from   aaa m where month=3   and m.year=aaa.year) as m3,
    (select amount from   aaa m where month=4   and m.year=aaa.year) as m4
    from aaa   group by year

    6. 复制表( 只复制结构, 源表名:a 新表名:b) 
    SQL: select * into b from a where 1<>1       (where1=1,拷贝表结构和数据内容)
    ORACLE:create table b

    As

    Select * from a where 1=2 

    [<>(不等于)(SQL Server Compact)

    比较两个表达式。 当使用此运算符比较非空表达式时,如果左操作数不等于右操作数,则结果为 TRUE。 否则,结果为 FALSE。]

     

    7. 拷贝表( 拷贝数据, 源表名:a 目标表名:b) 

    SQL: insert into b(a, b, c) select d,e,f from a; 

     

    8. 说明:日程安排提前五分钟提醒 
    SQL: select * from 日程安排 where datediff('minute',f 开始时间,getdate())>5 

     

    9. 两张关联表,删除主表中已经在副表中没有的信息 
    SQL: 
    Delete from info where not exists (select * from infobz where info.infid=infobz.infid )

  • 相关阅读:
    类加载机制的学习4___类加载的过程
    类加载机制的学习3___自定义的类加载器
    类加载机制的学习2_____双亲委派模型
    使用.NET读取exchange邮件
    SSMS错误:A connection was successfully established with the server, but then an error occurred during the login process
    收缩数据库 DBCC SHRINKFILE
    How to: Change Sales Rep/Team via Mass Update
    Microsoft.Office.Interop.Word.Document.Open returns null on Windows Server 2008 R2
    设置文件夹的权限
    NetSuite API
  • 原文地址:https://www.cnblogs.com/hushzhang/p/6964348.html
Copyright © 2011-2022 走看看