• Oracle-学习笔记(==》集合函数与分组四)


    -- 聚集函数 配合分组语句 group by
    -- 显示最高分
    SELECT MAX(sscore) FROM db.`student`;
    -- 显示最高分学生的信息min max
    SELECT * FROM db.`student` WHERE sscore IN(SELECT MAX(sscore) FROM db.`student`);

    -- 统计人数 (不是信息)
    SELECT COUNT(*) FROM db.`student`;
    SELECT COUNT(*) FROM db.`student` WHERE sscore<60;;
    SELECT AVG(sscore) 平均分,MAX(sscore) 最高分,MIN(sscore) 最低分 FROM student;
    SELECT COUNT(*) FROM student WHERE sscore IS NULL;
    SELECT COUNT(*) FROM student WHERE saddress IS NULL;


    UPDATE student SET sscore=NULL WHERE sscore=0;


    SELECT SUM(sage)FROM student;
    SELECT AVG(sage)FROM student;

    SELECT * FROM student;

    -- 统计各地区的人数
    SELECT COUNT(*) FROM student WHERE saddress='郑州';

    SELECT sscore 分数,COUNT(*) 人数
    FROM student
    WHERE saddress IS NOT NULL -- 查询条件
    GROUP BY sscore -- 分组字段
    HAVING COUNT(*)>4 -- 分组条件(符合条件才会分组)
    ORDER BY COUNT(*) DESC;-- desc降序排列

    SELECT saddress,COUNT(*),MAX(sscore) FROM student GROUP BY saddress;

    -- 并集
    -- 求出郑州最高分学生信息
    SELECT * FROM student
    WHERE saddress='郑州'
    AND sscore IN(SELECT MAX(sscore) FROM student WHERE saddress='郑州');

    -- 上海最高分学生信息
    SELECT * FROM student
    WHERE saddress='上海'
    AND sscore IN(SELECT MAX(sscore) FROM student WHERE saddress='上海');
    ------------------------------------

    SELECT * FROM student
    WHERE saddress='郑州'
    AND sscore IN(SELECT MAX(sscore) FROM student WHERE saddress='郑州')
    UNION
    SELECT * FROM student
    WHERE saddress='武汉'
    AND sscore IN(SELECT MAX(sscore) FROM student WHERE saddress='武汉');

  • 相关阅读:
    java_爬虫_从腾讯视频播放界面爬取视频真实地址
    杂_小技巧_将网页上的内容通过亚马逊邮箱传到kindle中
    java_基础_接口和抽象类
    知乎上的50道SQL练习题
    第 4 章 WebDriver API
    第 2 章 测试环境搭建
    第 1 章 自动化测试基础
    【软件测试】9.QC管理学习(类禅道)学习
    01 Python简介、环境安装、变量、数据类型
    【MySQL面试指南】
  • 原文地址:https://www.cnblogs.com/huangf714/p/6148240.html
Copyright © 2020-2023  润新知