当前位置: 首页 > news >正文

基于asp网站开发 论文下载百度app

基于asp网站开发 论文,下载百度app,做纸浆的网站,做网站界面一般用什么来做多表查询 1.创建student和score表2.为student表和score表增加记录3.查询student表的所有记录4.查询student表的第2条到4条记录5.从student表查询所有学生的学号(id)、姓名(name)和院系(department)的信息6.…

多表查询

  • 1.创建student和score表
  • 2.为student表和score表增加记录
  • 3.查询student表的所有记录
  • 4.查询student表的第2条到4条记录
  • 5.从student表查询所有学生的学号(id)、姓名(name)和院系(department)的信息
  • 6.从student表中查询计算机系和英语系的学生的信息
  • 7.从student表中查询年龄18~22岁的学生信息
  • 8.从student表中查询每个院系有多少人
  • 9.从score表中查询每个科目的最高分
  • 10.查询李四的考试科目(c_name)和考试成绩(grade)
  • 11.用连接的方式查询所有学生的信息和考试信息
  • 12.计算每个学生的总成绩
  • 13.计算每个考试科目的平均成绩
  • 14.查询计算机成绩低于95的学生信息
  • 15.查询同时参加计算机和英语考试的学生的信息
  • 16.将计算机考试成绩按从高到低进行排序
  • 17.从student表和score表中查询出学生的学号,然后合并查询结果
  • 18.查询姓张或者姓王的同学的姓名、院系和考试科目及成绩
  • 19.查询都是湖南的学生的姓名、年龄、院系和考试科目及成绩

1.创建student和score表

CREATE  TABLE student (
id  INT(10)  NOT NULL  UNIQUE  PRIMARY KEY ,
name  VARCHAR(20)  NOT NULL ,
sex  VARCHAR(4) ,
birth  YEAR,
department  VARCHAR(20) ,
address  VARCHAR(50)
);
创建score表。SQL代码如下:
CREATE  TABLE score (
id  INT(10)  NOT NULL  UNIQUE  PRIMARY KEY  AUTO_INCREMENT ,
stu_id  INT(10)  NOT NULL ,
c_name  VARCHAR(20) ,
grade  INT(10)
);
mysql> create table student (->   id int(10) not null unique primary key,->    name varchar(20) not null,->   sex varchar(4),->   birth year,->   department varchar(20),->  address varchar(50)->  );
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> create table score (->   id int(10) not null unique primary key auto_increment,->   stu_id int(10) not null,->   c_name varchar(20),->    grade int(10)->    );
Query OK, 0 rows affected, 3 warnings (0.00 sec)mysql> show tables;
+---------------+
| Tables_in_cla |
+---------------+
| score         |
| student       |
+---------------+
2 rows in set (0.00 sec)

2.为student表和score表增加记录

向student表插入记录的INSERT语句如下:
INSERT INTO student VALUES( 901,'张老大', '男',1985,'计算机系', '北京市海淀区');
INSERT INTO student VALUES( 902,'张老二', '男',1986,'中文系', '北京市昌平区');
INSERT INTO student VALUES( 903,'张三', '女',1990,'中文系', '湖南省永州市');
INSERT INTO student VALUES( 904,'李四', '男',1990,'英语系', '辽宁省阜新市');
INSERT INTO student VALUES( 905,'王五', '女',1991,'英语系', '福建省厦门市');
INSERT INTO student VALUES( 906,'王六', '男',1988,'计算机系', '湖南省衡阳市');
向score表插入记录的INSERT语句如下:
INSERT INTO score VALUES(NULL,901, '计算机',98);
INSERT INTO score VALUES(NULL,901, '英语', 80);
INSERT INTO score VALUES(NULL,902, '计算机',65);
INSERT INTO score VALUES(NULL,902, '中文',88);
INSERT INTO score VALUES(NULL,903, '中文',95);
INSERT INTO score VALUES(NULL,904, '计算机',70);
INSERT INTO score VALUES(NULL,904, '英语',92);
INSERT INTO score VALUES(NULL,905, '英语',94);
INSERT INTO score VALUES(NULL,906, '计算机',90);
INSERT INTO score VALUES(NULL,906, '英语',85);
mysql>  INSERT INTO student VALUES( 902,'张老二', '男',1986,'中文系', '北京市昌平区');
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO student VALUES( 903,'张三', '女',1990,'中文系', '湖南省永州市'); 
Query OK, 1 row affected (0.01 sec)
mysql>  INSERT INTO student VALUES( 904,'李四', '男',1990,'英语系', '辽宁省阜新市'); 
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO student VALUES( 905,'王五', '女',1991,'英语系', '福建省厦门市'); 
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO student VALUES( 906,'王六', '男',1988,'计算机系', '湖南省衡阳市');
Query OK, 1 row affected (0.00 sec)mysql> select * from student;
+-----+-----------+------+-------+--------------+--------------------+
| id  | name      | sex  | birth | department   | address            |
+-----+-----------+------+-------+--------------+--------------------+
| 901 | 张老大    ||  1985 | 计算机系     | 北京市海淀区       |
| 902 | 张老二    ||  1986 | 中文系       | 北京市昌平区       |
| 903 | 张三      ||  1990 | 中文系       | 湖南省永州市       |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       |
| 905 | 王五      ||  1991 | 英语系       | 福建省厦门市       |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |
+-----+-----------+------+-------+--------------+--------------------+
6 rows in set (0.00 sec)mysql>  INSERT INTO score VALUES(NULL,901, '英语', 80);
Query OK, 1 row affected (0.01 sec)
mysql>  INSERT INTO score VALUES(NULL,902, '计算机',65);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,902, '中文',88);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,903, '中文',95);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,904, '计算机',70);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,904, '英语',92);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,905, '英语',94);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,906, '计算机',90);
Query OK, 1 row affected (0.00 sec)
mysql>  INSERT INTO score VALUES(NULL,906, '英语',85);
Query OK, 1 row affected (0.01 sec)mysql> select * from score;
+----+--------+-----------+-------+
| id | stu_id | c_name    | grade |
+----+--------+-----------+-------+
|  1 |    901 | 计算机    |    98 |
|  2 |    901 | 英语      |    80 |
|  3 |    902 | 计算机    |    65 |
|  4 |    902 | 中文      |    88 |
|  5 |    903 | 中文      |    95 |
|  6 |    904 | 计算机    |    70 |
|  7 |    904 | 英语      |    92 |
|  8 |    905 | 英语      |    94 |
|  9 |    906 | 计算机    |    90 |
| 10 |    906 | 英语      |    85 |
+----+--------+-----------+-------+
10 rows in set (0.00 sec)

3.查询student表的所有记录

mysql> select id, name, department from student;
+-----+-----------+--------------+
| id  | name      | department   |
+-----+-----------+--------------+
| 901 | 张老大    | 计算机系     |
| 902 | 张老二    | 中文系       |
| 903 | 张三      | 中文系       |
| 904 | 李四      | 英语系       |
| 905 | 王五      | 英语系       |
| 906 | 王六      | 计算机系     |
+-----+-----------+--------------+
6 rows in set (0.00 sec)

4.查询student表的第2条到4条记录

mysql> select * from student limit 2,4;
+-----+-----------+------+-------+--------------+--------------------+
| id  | name      | sex  | birth | department   | address            |
+-----+-----------+------+-------+--------------+--------------------+
| 903 | 张三      ||  1990 | 中文系       | 湖南省永州市       |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       |
| 905 | 王五      ||  1991 | 英语系       | 福建省厦门市       |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |
+-----+-----------+------+-------+--------------+--------------------+
6 rows in set (0.00 sec)

5.从student表查询所有学生的学号(id)、姓名(name)和院系(department)的信息

mysql> select id, name, department from student;
+-----+-----------+--------------+
| id  | name      | department   |
+-----+-----------+--------------+
| 901 | 张老大    | 计算机系     |
| 902 | 张老二    | 中文系       |
| 903 | 张三      | 中文系       |
| 904 | 李四      | 英语系       |
| 905 | 王五      | 英语系       |
| 906 | 王六      | 计算机系     |
+-----+-----------+--------------+
6 rows in set (0.00 sec)

6.从student表中查询计算机系和英语系的学生的信息

mysql> select * from student where department='计算机系' or department='英语系';
+-----+-----------+------+-------+--------------+--------------------+
| id  | name      | sex  | birth | department   | address            |
+-----+-----------+------+-------+--------------+--------------------+
| 901 | 张老大    ||  1985 | 计算机系     | 北京市海淀区       |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       |
| 905 | 王五      ||  1991 | 英语系       | 福建省厦门市       |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |
+-----+-----------+------+-------+--------------+--------------------+
4 rows in set (0.00 sec)

7.从student表中查询年龄18~22岁的学生信息

8.从student表中查询每个院系有多少人

mysql> select department, count(*) as count from student group by department;
+--------------+-------+
| department   | count |
+--------------+-------+
| 计算机系     |     2 |
| 中文系       |     2 |
| 英语系       |     2 |
+--------------+-------+
3 rows in set (0.01 sec)

9.从score表中查询每个科目的最高分

mysql> select c_name, max(grade) as max_grade from score group by c_name;
+-----------+-----------+
| c_name    | max_grade |
+-----------+-----------+
| 计算机    |        98 |
| 英语      |        94 |
| 中文      |        95 |
+-----------+-----------+
3 rows in set (0.01 sec)

10.查询李四的考试科目(c_name)和考试成绩(grade)

mysql> select c_name, grade-> from score-> where stu_id = 904;
+-----------+-------+
| c_name    | grade |
+-----------+-------+
| 计算机    |    70 |
| 英语      |    92 |
+-----------+-------+
2 rows in set (0.00 sec)

11.用连接的方式查询所有学生的信息和考试信息

mysql>   select s.id, s.name, s.sex, s.birth, s.department, s.address, sc.c_name, sc.grade from student s join score sc on s.id = sc.stu_id;
+-----+-----------+------+-------+--------------+--------------------+-----------+-------+
| id  | name      | sex  | birth | department   | address            | c_name    | grade |
+-----+-----------+------+-------+--------------+--------------------+-----------+-------+
| 901 | 张老大    ||  1985 | 计算机系     | 北京市海淀区       | 计算机    |    98 |
| 901 | 张老大    ||  1985 | 计算机系     | 北京市海淀区       | 英语      |    80 |
| 902 | 张老二    ||  1986 | 中文系       | 北京市昌平区       | 计算机    |    65 |
| 902 | 张老二    ||  1986 | 中文系       | 北京市昌平区       | 中文      |    88 |
| 903 | 张三      ||  1990 | 中文系       | 湖南省永州市       | 中文      |    95 |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       | 计算机    |    70 |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       | 英语      |    92 |
| 905 | 王五      ||  1991 | 英语系       | 福建省厦门市       | 英语      |    94 |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       | 计算机    |    90 |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       | 英语      |    85 |
+-----+-----------+------+-------+--------------+--------------------+-----------+-------+
10 rows in set (0.00 sec)

12.计算每个学生的总成绩

mysql> select stu_id, sum(grade) as total_score from score group by stu_id;
+--------+-------------+
| stu_id | total_score |
+--------+-------------+
|    901 |         178 |
|    902 |         153 |
|    903 |          95 |
|    904 |         162 |
|    905 |          94 |
|    906 |         175 |
+--------+-------------+
6 rows in set (0.00 sec)

13.计算每个考试科目的平均成绩

mysql> select c_name, avg(grade) as average_score from score group by c_name;
+-----------+---------------+
| c_name    | average_score |
+-----------+---------------+
| 计算机    |       80.7500 |
| 英语      |       87.7500 |
| 中文      |       91.5000 |
+-----------+---------------+
3 rows in set (0.00 sec)

14.查询计算机成绩低于95的学生信息

mysql> select s.id, s.name, s.sex, s.birth, s.department, s.address, sc.grade-> from student s-> join score sc on s.id = sc.stu_id-> where sc.c_name = '计算机' and sc.grade < 95;
+-----+-----------+------+-------+--------------+--------------------+-------+
| id  | name      | sex  | birth | department   | address            | grade |
+-----+-----------+------+-------+--------------+--------------------+-------+
| 902 | 张老二    ||  1986 | 中文系       | 北京市昌平区       |    65 |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       |    70 |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |    90 |
+-----+-----------+------+-------+--------------+--------------------+-------+
3 rows in set (0.01 sec)

15.查询同时参加计算机和英语考试的学生的信息

mysql>  select s.id, s.name, s.sex, s.birth, s.department, s.address-> from student s-> join score sc1 on s.id = sc1.stu_id-> join score sc2 on s.id = sc2.stu_id-> where sc1.c_name = '计算机' and sc2.c_name = '英语';
+-----+-----------+------+-------+--------------+--------------------+
| id  | name      | sex  | birth | department   | address            |
+-----+-----------+------+-------+--------------+--------------------+
| 901 | 张老大    ||  1985 | 计算机系     | 北京市海淀区       |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |
+-----+-----------+------+-------+--------------+--------------------+
3 rows in set (0.00 sec)

16.将计算机考试成绩按从高到低进行排序

mysql> select s.name, s.sex, s.birth, s.department, s.address, sc.grade-> from student s-> join score sc on s.id = sc.stu_id-> where sc.c_name = '计算机'-> order by sc.grade desc;
+-----------+------+-------+--------------+--------------------+-------+
| name      | sex  | birth | department   | address            | grade |
+-----------+------+-------+--------------+--------------------+-------+
| 张老大    ||  1985 | 计算机系     | 北京市海淀区       |    98 |
| 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |    90 |
| 李四      ||  1990 | 英语系       | 辽宁省阜新市       |    70 |
| 张老二    ||  1986 | 中文系       | 北京市昌平区       |    65 |
+-----------+------+-------+--------------+--------------------+-------+
4 rows in set (0.00 sec)

17.从student表和score表中查询出学生的学号,然后合并查询结果

mysql>  select id from student-> union-> select stu_id from score;
+-----+
| id  |
+-----+
| 901 |
| 902 |
| 903 |
| 904 |
| 905 |
| 906 |
+-----+
6 rows in set (0.00 sec)

18.查询姓张或者姓王的同学的姓名、院系和考试科目及成绩

mysql> select s.name, s.department, sc.c_name, sc.grade-> from student s-> join score sc on s.id = sc.stu_id-> where s.name like '张%' or s.name like '王%';
+-----------+--------------+-----------+-------+
| name      | department   | c_name    | grade |
+-----------+--------------+-----------+-------+
| 张老大    | 计算机系     | 计算机    |    98 |
| 张老大    | 计算机系     | 英语      |    80 |
| 张老二    | 中文系       | 计算机    |    65 |
| 张老二    | 中文系       | 中文      |    88 |
| 张三      | 中文系       | 中文      |    95 |
| 王五      | 英语系       | 英语      |    94 |
| 王六      | 计算机系     | 计算机    |    90 |
| 王六      | 计算机系     | 英语      |    85 |
+-----------+--------------+-----------+-------+
8 rows in set (0.01 sec)

19.查询都是湖南的学生的姓名、年龄、院系和考试科目及成绩

mysql>  select s.name, year(curdate())-s.birth as age, s.department, sc.c_name, sc.grade-> from student s-> join score sc on s.id = sc.stu_id-> where s.address like '%湖南%';
+--------+------+--------------+-----------+-------+
| name   | age  | department   | c_name    | grade |
+--------+------+--------------+-----------+-------+
| 张三   |   34 | 中文系       | 中文      |    95 |
| 王六   |   36 | 计算机系     | 计算机    |    90 |
| 王六   |   36 | 计算机系     | 英语      |    85 |
+--------+------+--------------+-----------+-------+
3 rows in set (0.00 sec)
http://www.dt0577.cn/news/10120.html

相关文章:

  • 安乡网站制作外贸网站制作
  • 做网站可以做哪些方面的重庆seo公司怎么样
  • 如何推销网站建设优化营商环境个人心得
  • 本子网站建设深圳优化服务
  • 衡水做网站的网站排名优化软件有哪些
  • 济南网站建设优化免费发布广告信息的网站
  • 帝国cms网站地图xml百度贴吧入口
  • 济宁专业做优化的网站yahoo搜索
  • wordpress更换网页logo南昌网站seo外包服务
  • 西安注册公司流程免费seo网站自动推广
  • 通用网站后台管理系统(php版) 1.6怎么用关键词挖掘
  • 规划设计导航网站营销软文500字
  • 黑人做爰视频免费网站加强服务保障满足群众急需i
  • 肇庆市企业网站建设品牌广东宣布即时优化调整
  • wordpress注册邮箱设置seo外包服务公司
  • 做兼职什么网站网站设计公司模板
  • 马尼拉做网站谷歌搜索引擎免费入口 香港
  • 青岛商媒做网站怎么样电商平台怎么做
  • 哪里可以学做网站产品市场营销策划书
  • 做的网站怎样评估价值seo渠道
  • 上海网站建设hxwlkj长沙做引流推广的公司
  • wordpress做电商网站免费下载百度app最新版本
  • 广州网站建设360元国产最好的a级suv88814
  • 做微信的网站叫什么软件千锋教育官方网
  • wordpress 批量建站全球外贸b2b网站
  • 深圳专业做网站排名公司学校招生网络营销方案
  • 房地产楼盘微信网站建设营销方案漂亮的网页设计
  • 卖产品的网站怎么做响应式网站模板的优势
  • 专业做外贸网站建设关键词seo优化公司
  • 颍泉网站建设百度帐号