• select基础查询


    select查询

    请添加图片描述

    distinct取消重复

    create table student(
    	id int not null default 1,
    	name varchar(20) not null default '',
    	chinese float not null default 0.0,
    	english float not null default 0.0,
    	math float not null default 0.0
    )
    
    insert into student(id,name,chinese,english,math) values (1,'ymm',89,78,99);
    insert into student(id,name,chinese,english,math) values(2,'hh',99,89,88);
    insert into student(id,name,chinese,english,math) values(3,'yxc',90,99,90);
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    1. 查询表中所有学生的信息
    2. 查询表中所有学生的姓名和对应的英语成绩
    3. 过滤表中重复的数据 distinct
    4. 要查询的记录,每个字段都相同,才会去重
    -- select 查询
    select * from student;
    select name,english from student;
    select distinct * from student;
    select distinct chinese from student;
    select distinct name,chinese from student;
    -- 要查询的记录,每个字段都相同,才会去重
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    使用表达式进行运算,使用as语句

    请添加图片描述

    1. 统计每个学生的总分
    2. 在所有学生总分加10分的情况
    3. 使用别名表示学生的数学分数
    -- 总分
    select `name`,(chinese+english+math) from student;
    select `name`,(chinese+english+math+10) from student;
    
    select `name`,(chinese+english+math) as total from student;
    select `name` as '名字',(chinese+english+math) from student;
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在where子句中使用运算符

    请添加图片描述

    -- where
    select * from student where `name` = 'ymm';
    select * from student where `english` >90;
    select * from student where (chinese+english+math) > 200;
    
    • 1
    • 2
    • 3
    • 4
    -- 查询math>60 并且 english > 90
    select * from student where `math`>60 and `english`>90;
    
    -- 查询总分大于200并且math大于chinese的首字母为y的学生
    select * from student where (chinese+math+english) > 200 and math>chinese and `name` like 'y%';
    
    -- 查询English在80到90分之间的
    select * from student where english between 80 and 90; -- 闭区间
    select * from student where english >=80 and english <= 90;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    使用order by子句排序查询

    请添加图片描述

    升序:Ascending order

    降序:Descending order

    -- 排序
    select * from student order by math;
    
    -- 总分降序
    select * from student order by (chinese + math + english) desc;
    -- 首字母为y升序
    select * from student where `name` like 'y%' order by (chinese+math+english);
    
    select `name`,(chinese+english+math) as total from student where `name` like 'y%' order by total;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    并行Stream的性能测试
    GPT-人工智能如何改变我们的编码方式
    【一起学Rust | 框架篇 | ws-rs框架】属于Rust的Websocket框架——ws-rs
    不同规模的企业如何借助宁盾LDAP统一用户认证实现安全和效率需求?
    msvcp120.dll缺失的解决方法与作用介绍
    基于springboot实现校园医疗保险管理系统【项目源码】
    QUIC 与 防火墙
    使用cython加速代码运行
    【C++】unordered_set、unordered_map的介绍及使用
    Go中的泛型和反射以及序列化
  • 原文地址:https://blog.csdn.net/weixin_45920495/article/details/127702949