zoukankan      html  css  js  c++  java
  • mysql面试题目1

    有这样一个成绩表,学生A,B,C,三个人,考试科目分别为C(chinese),M(math),E(english)

    求三门课成绩都大于80分的那个学生姓名:

    即查询的方法可分为俩种:select name from class3 group by name having min(grade)>80

    或者select distinct name from class3 where name not in (select distinct name from class3 where grade<80)

    2.删除表中除了stu_id不同,其它都相同的信息

     sql用法:

    Delete from class3 where stu_id not in (select min(stu_id) from class3 group by name,project,grade);

    但是由于mysql自身的原因,执行此用法的时候,报错。

    mysql:

    DELETE from class3 where stu_id not in (select bid from (select min(stu_id) as bid from class3 GROUP by name,project,grade)as b);

     

    总之原理就是:将表中的数据按除stu_id之外的所有列进行分组   之后每个组的数据就是除了stu_id都相同的数据了   这样每个组只需保留一条记录即可  这是使用max(stu_id)或者min(stu_id)都可以 总之只要从每组取出一个stu_id即可  然后将整个表中的记录stu_id不在所选择出的stu_id之列的全部删除即可 

  • 相关阅读:
    iOS热更新-8种实现方式
    HTTPS分析-简单易懂
    猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
    iOS的ATS配置
    Objective-C中block的底层原理
    iOS系列文章
    UIViewController生命周期-完整版
    缩放因子和UI设计
    iOS APP 如何做才安全
    逆向工程
  • 原文地址:https://www.cnblogs.com/ConnorShip/p/9927602.html
Copyright © 2011-2022 走看看