A04 - 007、数据库表内容操作 - 查

版权声明:本文为博主原创文章,未经允许不得转载。 https://blog.csdn.net/weixin_42464054/article/details/91129705

0、本章学习目录大纲 - 查

初学耗时:1h

注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。

一、数据库表内容操作 - 查
  1.1  创建数据库,并向数据库表中插入数据。
  1.2  查询学生的所有信息。
  1.3  查询所有学生的姓名和成绩。
  1.4  查询表中年龄大于等于24岁的学生信息。
  1.5  查询年龄不是25岁的学生。
  1.6  查询年龄>23,并且成绩>80的同学信息。
  1.7  查询成绩在80~100(包含)之间的学生信息。
  1.8  查询成绩在80~100(包含)之间的学生信息。
  1.9  查询年龄为18,23,25的同学信息。
  1.10  查询所有含有"岩”的学生信息。
  1.11  查询没有生日学员信息。就是生日是null。
  1.12  查询有年龄学员信息。就是年龄不是空。
  1.13  显示不重复的年龄。
  1.14  对成绩排序后输出。
  1.15  对年龄排序按从高到低(降序)的顺序输出。
  1.16  对学生年龄按照降序排序,年龄相同按照成绩降序。
  1.17  给年龄和分数起别名。
  1.18  省略关键as 再次查询。

二、面试题
    2.1  上述SQL语句有什么区别?



  • 1、A04系列全套网盘资源:

ギ 舒适区ゾ || ♂ 累觉无爱 ♀





一、数据库表内容操作 - 查

  1.1 ~ 创建数据库,并向数据库表中插入数据。

create database day02;

use day02;

create table student(
	id int primary key auto_increment,
    name varchar(32) not null,
	age int ,
	gender varchar(10) not null,
	score double not null,
	birthday date
);

insert into student (id,name,age,gender,score,birthday) values(null,'zhangsan',23,'male',98.99,'1990-09-09');
insert into student (id,name,age,gender,score,birthday) values(null,'lisi',23,'男',56.99,'1990-02-09');
insert into student (id,name,age,gender,score,birthday) values(null,'王五',24,'女',75.99,'1988-01-01');
insert into student (id,name,age,gender,score,birthday) values(null,'赵六',25,'男',80.99,'1980-11-12');
insert into student (id,name,age,gender,score,birthday) values(null,'柳岩',null,'女',84,null);

  1.2 ~ 查询学生的所有信息。

查询一般在可视化工具里。

select * from student;

  1.3 ~ 查询所有学生的姓名和成绩。

select name,score from student;

  1.4 ~ 查询表中年龄大于等于24岁的学生信息。

select * from student where age >= 24;

  1.5 ~ 查询年龄不是25岁的学生。

select * from student where age != 25;
select * from student where age <> 25;

  1.6 ~ 查询年龄>23,并且成绩>80的同学信息。

select * from student where age>23 and score>80;

  1.7 ~ 查询成绩在80~100(包含)之间的学生信息。

select * from student where score >= 80 and score <=100;

  1.8 ~ 查询成绩在80~100(包含)之间的学生信息。

select * from student where score>=80 and score<=100;
select * from student where score between 80 and 100;

  1.9 ~ 查询年龄为18,23,25的同学信息。

select * from student where age=18 or age=23 or age=25;
select * from student where age in(18,23,25);

  1.10 ~ 查询所有含有"岩”的学生信息。

select * from student where name like '%岩%';

  1.11 ~ 查询没有生日学员信息。就是生日是null。

select * from student where birthday is null;

  1.12 ~ 查询有年龄学员信息。就是年龄不是空。

select * from student where age is not null;

  1.13 ~ 显示不重复的年龄。

select distinct age from student;

  1.14 ~ 对成绩排序后输出。

select * from student order by score asc;

select * from student order by score desc;

  1.15 ~ 对年龄排序按从高到低(降序)的顺序输出。

select * from student order by age desc;

  1.16 ~ 对学生年龄按照降序排序,年龄相同按照成绩降序。

select * from student order by age desc,score desc;

  1.17 ~ 给年龄和分数起别名。

select age as 年龄,score as 分数 from student;

  1.18 ~ 省略关键as 再次查询。

select age 年龄,score 分数 from student;


尖酸刻薄的话少说,冲动任性的事少做。

- - - - - - - - - - - - - - - - - - - - - - - - - - - -


二、面试题

  2.1 ~ 上述SQL语句有什么区别?

1、select age , score from student;
2、select age score from student;

alt
alt

第一句sql查询两列,第二句sql只有一列,score为别名。


尖酸刻薄的话少说,冲动任性的事少做。

- - - - - - - - - - - - - - - - - - - - - - - - - - - -



^ 至此,数据库表内容操作 - 查完成。


- - - - - - - - - - - - - - - - - - - - - - - - - - - -


※ 世间诱惑何其多,坚定始终不动摇。

正常建立一条TCP连接需要()个步骤,正常关闭一个TCP连接需要()个步骤?


A、3,3
B、3,4
C、4,4
D、4,3

B
alt



尖酸刻薄的话少说,冲动任性的事少做。

- - - - - - - - - - - - - - - - - - - - - - - - - - - -


注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。

我知道我的不足,我也知道你的挑剔,但我就是我,不一样的烟火,谢谢你的指指点点,造就了我的点点滴滴:)!



尖酸刻薄的话少说,冲动任性的事少做。


猜你喜欢

转载自blog.csdn.net/weixin_42464054/article/details/91129705