表的创建、查询习题

1、设计一张图书表,包含以下字段:图书名称,图书作者、图书价格、图书分类

drop table if exists booklist;
create table booklist(
book_name varchar(50),
book_author varchar(30),
book_price decimal(4,2),
book_category varchar(20)
);

2、设计一张老师表,包含以下字段:姓名、年龄、身高、体重、性别、学历、生日、身份证号

drop table if exists teacher;
create table teacher(
name varchar(20),
age int,
height double,
weight double,
sex varchar(5),
degree varchar(20),
birthday timestamp,
id_number varchar(18)
);

3、设计一张商品表,包含以下字段:商品名称、商品价格、商品库存、商品描述

drop table if exist product;
create table product(
name varchar(20),
price decimal(11,2),
stock int,
description varchar(50));

4、在以上创建的商品表中插入一条数据:名称为“学生书包”、价格18.91、库存101、描述为空

insert into product values('学生书包',18.91,101,null);
insert into product(name,price,stock) values(('学生书包',18.91,101)

5、在图书表中新增一条记录:Java核心技术、作者“Cay S. Horstman”,价格56.43,分类为“计算机技术”

insert into booklist values('Java核心技术','cay s.horstman',56.43,'计算机技术');

6、student学生表中,字段有姓名name,年龄age,要求查询姓张,并且年龄在18到25岁之间的学生

select * from student where like '张%' and age between 18 and 25;

7、查询article文章表中,发表日期create_date在2019年1月1日上午10点30分至2019年11月10日下午4点2分的文章

select * from artical where create_date between '2019-01-01 10:30:00' and2019-11-10 16:02:00';

8、查询article文章表中,文章标题title为空,或者满足发表日期create_date在2019年1月1日之后

select * from artical where title is null or create_date > '2019-01-01 00:00:00';
select * from artical where title <=> null or create_date > '2019-01-01 00:00:00';
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一些 MySQL 多查询和连接查询的练习题,希望能帮到你: 1. 创建两个:`students` 和 `classes`。`students` 包含字段:`id`(主键,自增),`name`(字符串),`age`(整数),`class_id`(整数,外键,引用 `classes` 的 `id` 字段)。`classes` 包含字段:`id`(主键,自增),`name`(字符串),`teacher`(字符串)。 2. 向 `classes` 中插入 3 条记录,分别是:`id` 为 1,`name` 为 "Class1",`teacher` 为 "Teacher1";`id` 为 2,`name` 为 "Class2",`teacher` 为 "Teacher2";`id` 为 3,`name` 为 "Class3",`teacher` 为 "Teacher3"。 3. 向 `students` 中插入 4 条记录,分别是:`id` 为 1,`name` 为 "Tom",`age` 为 18,`class_id` 为 1;`id` 为 2,`name` 为 "Lucy",`age` 为 20,`class_id` 为 2;`id` 为 3,`name` 为 "Jack",`age` 为 19,`class_id` 为 3;`id` 为 4,`name` 为 "Mike",`age` 为 18,`class_id` 为 1。 4. 查询 `students` 中的所有记录,并显示每个学生的 `name`,`age`,以及所在班级的 `name` 和 `teacher`。 5. 查询 `classes` 中的所有记录,并显示每个班级的 `name`,`teacher`,以及该班级中的学生数目。 6. 查询 `students` 中每个班级的平均年龄,并按照平均年龄从大到小排序。 7. 查询 `classes` 中每个班级的平均成绩,并按照平均成绩从高到低排序。假设每个班级有若干个学生,每个学生有一个成绩,成绩存储在 `students` 中。 8. 查询 `classes` 中至少有两个学生的班级,显示这些班级的 `name` 和 `teacher`。 希望这些练习题能够帮助你熟悉 MySQL 多查询和连接查询的操作。如果你还有其他问题,可以随时问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值