zoukankan      html  css  js  c++  java
  • java面试题之sql语句

    根据这一张表进行sql操作

    -- 分组查询总分数
    select num,name,SUM(score) as scoreall from score2 GROUP BY name order by scoreall
    -- 计算每个人单科最高成绩
    select name,MAX(score) from score2 GROUP BY name
    -- 计算每个人的平均成绩
    select name,AVG(score) from score2 GROUP BY name
    -- 列出各科成绩最好的学生
    select DISTINCT '最高分',score2.* from score2,(select MAX(score) as score,course from score2 GROUP BY course ) b
    where score2.score=b.score

    -- 分组统计姓名 语文、数学、英语、总分、平均分
    select name as '姓名',SUM(case when course='语文' then score end) as '语文',SUM(case when course='数学' then score end)'数学',
    SUM(case when course='英语' then score end)'英语',SUM(score),AVG(score) FROM score2 GROUP BY name

    -- 列出数学成绩的排名
    select name,course,score from score2 where course='数学' order by score desc

    -- 统计课程和对应的优秀、及格、不及格个数
    select course,(select COUNT(*) from score2 where course=t.course and score>=80)'优秀',
    (select COUNT(*) from score2 where course=t.course and score>=60 and score<80)'良好',
    (select COUNT(*) from score2 where course=t.course and score<60)'不及格'
    from score2 t GROUP BY course

    -- 计算各科都及格的的人的平均成绩
    select name,AVG(score) from score2 GROUP BY name having MIN(score)>60

  • 相关阅读:
    UNP(2rd)第二卷源码编译
    A very hard mathematic problem
    并查集~
    N皇后问题 深搜dfs
    实践中的一点小问题
    java环境配置 HelloWorld
    精确时间计算方法
    C语言关于文件操作
    字典树应用~
    并查集应用2
  • 原文地址:https://www.cnblogs.com/jincheng81/p/9106228.html
Copyright © 2011-2022 走看看