云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > mysql查询语句综合实例

mysql查询语句综合实例

  • 62 次阅读
  • 3 次下载
  • 2025/6/16 8:09:08

查询综合实例

? 假设学生选课数据库有三个表即学生表S、课程表C和学生选课表SC,它们的结构如下所示,请根据所给的每种功能写出相应的查询语句。 S(S# ,SN ,SEX ,AGE ,DEPT) C(C# ,CN)

SC(S# ,C# ,GRADE)

其中:S#为学号,SN为姓名,SEX为性别,AGE为年龄,DEPT为系别,C#为课程号,CN为课程名,GRADE为课程成绩。

1、查询所有姓王的学生的姓名和性别。 2、统计学生选课数据库中开出的课程总数。

3、查询每个学生选修每门课程的有关课程数据(姓名、课程名和成绩等) 。 4、从学生选课库中查询出被2名以上(含2名)学生选修的所有课程信息。。

5、从学生选课库中查询出最多选修了1门课(含未选任何课程)的全部学生信息。 6、查询所有与“张鲁”同一性别的学生姓名、年龄和性别(假设库中只有一个学生的姓名为“张鲁”)。

7、从学生选课库中查询出每门课程被选修的学生人数,并按所选人数的降序排列出课程号和选课人数。

答案:

1.建表脚本:

/*==============================================================*/ /* DBMS name: MySQL 5.0 */ /* Created on: 2013-11-04 15:14:23 */ /*==============================================================*/

drop table if exists course;

drop table if exists sc;

drop index Index_2 on student;

drop table if exists student;

/*==============================================================*/ /* Table: course */ /*==============================================================*/ create table course (

couid int not null auto_increment, cno varchar(10) not null, cname varchar(30) not null, primary key (couid) );

/*==============================================================*/ /* Table: sc */ /*==============================================================*/ create table sc (

sid int not null auto_increment,

stuid int, couid int,

grade varchar(10) not null, primary key (sid) );

/*==============================================================*/ /* Table: student */ /*==============================================================*/ create table student (

stuid int not null auto_increment, stuno varchar(10) not null, stuname varchar(10) not null, sex varchar(10) not null, age int,

dept varchar(20), primary key (stuid) );

/*==============================================================*/ /* Index: Index_2 */ /*==============================================================*/ create unique index Index_2 on student (

stuname );

alter table sc add constraint FK_c_sc foreign key (couid)

references course (couid) on delete restrict on update restrict;

alter table sc add constraint FK_s_sc foreign key (stuid)

references student (stuid) on delete restrict on update restrict;

搜索更多关于: mysql查询语句综合实例 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

查询综合实例 ? 假设学生选课数据库有三个表即学生表S、课程表C和学生选课表SC,它们的结构如下所示,请根据所给的每种功能写出相应的查询语句。 S(S# ,SN ,SEX ,AGE ,DEPT) C(C# ,CN) SC(S# ,C# ,GRADE) 其中:S#为学号,SN为姓名,SEX为性别,AGE为年龄,DEPT为系别,C#为课程号,CN为课程名,GRADE为课程成绩。 1、查询所有姓王的学生的姓名和性别。 2、统计学生选课数据库中开出的课程总数。 3、查询每个学生选修每门课程的有关课程数据(姓名、课程名和成绩等) 。 4、从学生选课库中查询出被2名以上(含2名)学生选修的所有课程信息。。 5、从学生选课库中查询出最多选修了1门课(

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com