Create table student (

Sno char(15) primary key ,

Sname varchar(10) not null,

Sage tinyint ,

Special varchar(20),

Birth date,

Sex char(2)

);

insert into stu(sno,sname,sage,special,birth,sex) values

('st002','lisi',19,'CS','1999-1-2','M'),

('st003','wangwu',20,'CS','1998-1-2','M'),

('st004','zhaoliu',21,'art','1997-1-2','M'),

('st005','sunqi',22,'math','1996-1-2','F'),

('st006','lisi',35,'en','1983-1-2','F'),

('st007','jia',18,'CS','2000-1-2','M'),

('st008','peter',16,'edu','2002-1-2','F'),

('st009','hanmeimei',19,'art','1999-1-2','F'),

('st0010','poly',8,'CS','2008-1-2','F'),

('st0011','zhangliu',21,'art','1997-7-2','M'),

('st0012','wangliu',27,'art','1991-1-2','M'),

('st0013','liliu',26,'art','1992-1-2','F'),

('st0014','sunliu',20,'art','1998-1-2','F'),

('st0015','lisi',18,'CS','2000-1-2','F'),

('st0016','wangwu',20,'CS','1998-1-2','F'),

('st0017','lisi',17,'CS','2001-1-2','M'),

('st0018','wangwu',26,'CS','1992-1-2','M');

课前复习:

1查询表中学生的学号,姓名,年龄信息。

select sno,sname,sage from student;

2查询edu系所有女生的信息。

select * from student where Special ='edu' and Sex ='f';

3查询所有在1999年以后出生的学生的所有信息。

select * from student where birth>'1999-1-1';

select * from student where year(birth)>1999;

4.查询所有在2000年至2010年出生的所有学生的信息。

select * from student where Birth between '2000-1-1' and '2010-12-31';

select * from student where Birth>='2000-1-1' and Birth <='2010-12-31';

作业:

1.查询所有学生的最大,最小,平均年龄。

2.查询art系学生的最大,最小,平均年龄,。

3.查询各个系学生的最大,最小,平均年龄。

4.查询人数超过5的专业名称及人数。

5.按年龄从小到大查询所有人的信息。

6.按年龄从大到小查询所有人的信息。

7.按学号递减,年龄递增查询所有人的信息。

Create table student1 (

Sno char(15) primary key ,

Sname varchar(10) not null,

Sage tinyint ,

Special varchar(20),

Birth date,

Sex char(2)

);

select * from student1

insert into student1(sno,sname,sage,special,birth,sex) values

('st002','lisi',19,'CS','1999-1-2','M'),

('st003','wangwu',20,'CS','1998-1-2','M'),

('st004','zhaoliu',21,'art','1997-1-2','M'),

('st005','sunqi',22,'math','1996-1-2','F'),

('st006','lisi',35,'en','1983-1-2','F'),

('st007','jia',18,'CS','2000-1-2','M'),

('st008','peter',16,'edu','2002-1-2','F'),

('st009','hanmeimei',19,'art','1999-1-2','F'),

('st010','poly',8,'CS','2008-1-2','F'),

('st011','zhangliu',21,'art','1997-7-2','M'),

('st012','wangliu',27,'art','1991-1-2','M'),

('st013','liliu',26,'art','1992-1-2','F'),

('st014','sunliu',20,'art','1998-1-2','F'),

('st015','lisi',18,'CS','2000-1-2','F'),

('st016','wangwu',20,'CS','1998-1-2','F'),

('st017','lisi',17,'CS','2001-1-2','M'),

('st018','wangwu',26,'CS','1992-1-2','M');

/1.查询所有学生的最大,最小,平均年龄/

select AVG(sage) as AVG, MAX(sage) as MAX,MIN(sage) as MIN from student1;

/2. 查询art系学生的最大,最小,平均年龄/

select MAX(sage) as MAXage,MIN(sage) as MINage,AVG(sage) as AVGage from student1 where Special='art';

/* 3.查询各个系学生的最大,最小,平均年龄。 /

select MAX(sage) as MAXage,MIN(sage) as MINage,AVG(sage) as AVGage from student1 group by Special ;

/
4.查询人数超过5的专业名称及人数。/

select Special ,count(
) as [专业人数]from student1 group by Special HAVING COUNT() > 5;

/
5.按年龄从小到大查询所有人的信息。/

select sno,sname,sage,special,birth,sex from student1 order by sage asc;

/
6.按年龄从大到小查询所有人的信息。 /

select sno,sname,sage,special,birth,sex from student1 order by sage desc;

/
7.按学号递减,年龄递增查询所有人的信息。/

select sno,sname,sage,special,birth,sex from student1 order by sno desc ,Sage asc;

/
表名自行修改为了student1,学号应该是三位 将原数据 如st0018改为st018否则按原来的学号无法递减排序*/

数据库4m10d作业的更多相关文章

  1. 数据库大作业--由python+flask

    这个是项目一来是数据库大作业,另一方面也算是再对falsk和python熟悉下,好久不用会忘很快. 界面相比上一个项目好看很多,不过因为时间紧加上只有我一个人写,所以有很多地方逻辑写的比较繁琐,如果是 ...

  2. SqlServer批量压缩数据库日志-多数据库批量作业,批量备份还原

    原文:SqlServer批量压缩数据库日志-多数据库批量作业,批量备份还原 --作业定时压缩脚本 多库批量操作 DECLARE @DatabaseName NVARCHAR(50) DECLARE @ ...

  3. python学习之老男孩python全栈第九期_数据库day001 -- 作业

    创建如图所示数据库: 创建过程:  查看数据库,创建数据库 db1,再查看一下数据库  进入数据库,查看一下表  接着再创建一个class表 发现增加了重复数据,因此要把第二个修改一下  修改完数据之 ...

  4. 使用SQL Server Management Studio 创建数据库备份作业

    --完整备份,每周一次USE MasterGOdeclare @str varchar(100)set @str='D:\Weldon\DBBACK\FullBak'+replace(replace( ...

  5. 关于SQLite数据库的作业

    数据库的SQL预览代码我忘了复制了 只能截图 Students表: Course表: Score表: Teachcer表:

  6. SQL Server数据库(作业讲解和复习)

    --第一题 查询Student表中的所有记录的Sname.Ssex和Class列.select Sname,Ssex,Class from student --第二题 查询教师所有的单位即不重复的De ...

  7. 本地SQL数据库执行作业定时修改其他数据库内容

    --exec sp_addlinkedserver 'xkp', ' ', 'SQLOLEDB', '192.168.66.66'  定义链接--exec sp_addlinkedsrvlogin ' ...

  8. python学习之老男孩python全栈第九期_数据库day003 -- 作业

    数据库: class:  course: student: teacher: score: /* Navicat Premium Data Transfer Source Server : local ...

  9. 数据库备份作业的T-SQL语句

    1.关于大容量数据导入导出的一些方法SQL SERVER提供多种工具用于各种数据源的数据导入导出,这些数据源包括本文文件.ODBC数据源.OLE DB数据源.ASCII文本文件和EXCEL电子表格.2 ...

随机推荐

  1. 新概念英语(1-57)An unusual day

    新概念英语(1-57)An unusually day What is Mr. Sawyer doing tonight? It is eight o'clock. The children go t ...

  2. python 类知识点总结

    python 类知识点总结 面向对象思想: 1.设计的时候,一定要明确应用场景 2.由对象分析定义类的时候,找不到共同特征和技能不用强求 1.简述类.对象.实例化.实例这些名词的含义: 类:从一组对象 ...

  3. POJ-1789 Truck History---最小生成树Prim算法

    题目链接: https://vjudge.net/problem/POJ-1789 题目大意: 用一个7位的string代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数.一 ...

  4. spring boot 系列之三:spring boot 整合JdbcTemplate

    前面两篇文章我们讲了两件事情: 通过一个简单实例进行spring boot 入门 修改spring boot 默认的服务端口号和默认context path 这篇文章我们来看下怎么通过JdbcTemp ...

  5. The first week CorelDRAW 课总结:

    1.这节课学到了什么知识? 答:(1)认识了CorelDRAW X4的工作界面(由标题栏 菜单栏 工具栏 属性栏 工具箱 页面控制栏 状态栏 绘图区和调色板组成): (2)CorelDRAW X4的基 ...

  6. 典型分布式系统分析之MapReduce

    在 <分布式学习最佳实践:从分布式系统的特征开始(附思维导图)>一文中,提到学习分布式系统的一个好方法是思考分布式系统要解决的问题,有哪些衡量标准,为了解决这些问题:提出了哪些理论.协议. ...

  7. MongoDB系列六(聚合).

    一.概念 使用聚合框架可以对集合中的文档进行变换和组合.基本上,可以用多个构件创建一个管道(pipeline),用于对一连串的文档进行处理.这些构件包括筛选(filtering).投射(project ...

  8. java---interrupt、interrupted和isInterrupted的区别

    1.interrupt()  interrupt方法用于中断线程.调用该方法的线程的状态为将被置为"中断"状态. 注意:线程中断仅仅是置线程的中断状态位,不会停止线程.需要用户自己 ...

  9. [LeetCode] Find Duplicate File in System 在系统中寻找重复文件

    Given a list of directory info including directory path, and all the files with contents in this dir ...

  10. [LeetCode] Base 7 基数七

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...