数据库简单练习 建表+select
sno int primary key,
sname char(20),
sex char(2),
birthday datetime,
class int
)
create table teacher (
tno int primary key,
tname char(20),
sex char(2),
birthday datetime,
prof char(10),
depart char(20)
)
create table course (
cno char(20) primary key,
cname char(20),
tno int foreign key references teacher(tno)
)
create table score (
sno int foreign key references student(sno),
cno char(20) foreign key references course(cno),
degree int
)
insert into student values(108,'曾华','男','09/01/1977',95033);
insert into student values(105,'匡明','男','10/02/1975',95031);
insert into student values(107,'王丽','女','01/23/1976',95033);
insert into student values(101,'李军','男','02/20/1976',95033);
insert into student values(109,'王芳','女','02/10/1975',95031);
insert into student values(103,'陆军','男','06/03/1974',95031);
insert into teacher values(831,'刘冰','女','08/14/1977','助教','电子工程系');
insert into course values('3-105','计算机导论',825);
insert into score values(103,'3-245',86);
insert into score values(109,'3-245',68);
insert into score values(105,'3-105',88);
insert into score values(109,'3-105',76);
drop table teacher
drop table course
drop table score
--1、列出student表中所有记录的
--sname、sex和class列。
select sname,sex,class from student
--select * from score where degree>=60 and degree<=80
--select * from score where degree in (85,86,88)
--select *from student where class='95033'and sex='女'
-- select * from student order by class desc
-- select * from student order by cno asc,degree desc
--select COUNT(*),COUNT(sno)from student where class='95033'
--select max(degree),nim(degree),avg(degree) from score
--select * from score where degree=(select max(degree) from score)
--select cno,count(*),AVG(degree) from score where cno like '3%' group by cno having count(cno)>=5
--select sno from score group by sno having max(degree)<90 and min(degree)>70
--select sno from score where max(degree)<90 and min(degree)>70
--select sname、cno、degree from score,student where student.sno=score.sno
--select sname、cno、degree from score join student on student.sno=score.sno
--select sname,cname,DEGREE from student,score,course where student.sno=score.sno and score.cno=course.cno
--select sname,cname,DEGREE from student join score on student.sno=score.sno join course on score.cno=course.cno
--select avg(degree) from score where sno in (select sno from student where class='95033')
--select * from score where degree>(select degree from score where sno=109 and cno='3-105') and cno ='3-105'
--select sno,sname,birthday from student where day(birthday)= (select day(birthday) from student where sno=108)
--select * from score where cno=(select cno form course where tno=(select tno from teacher where tname='XXX'))
--select tracher.* ,course.* ,score.* from teacher,course,score where teacher.tno=course.tno and course.cno=score.cno and tname='XXX'
--select tracher.* ,course.* ,score.* from teacher join course on teacher.tno=course.tno join score on course.cno=score.cno where tname='XXX'
--select tname from teacher where tno in(select tno from course where cno in(select cno from score group by cno having count(*)>=5))
--select * from student where class ='95033' or class='95031'
--select distindt cno from score where degree>85
-- 相同的显示一次
--select * from score where cno in(select cno from course where tno in(select tno from teacher where depart ='计算机系'))
--select cno,sno,degree from score where cno='3-105' and degree>any(select degree from c=score where cno='2_245')
--select cno,sno,degree from score where cno='3-105' and degree>(select min(degree) from c=score where cno='2_245')
--29、列出所有任课老师的tname和depart
--select tname,depart from teacher where tno in(select tno from course)
--select tname,depart from teacher where tno not in(select tno from course)
--select sname,sex,birthday from student union select tname,sex,birthday from teacher
--select distinct sno from score x where not exists(select * from score y where y.sno=103 and not exists(select * from score z where z.sno=x.sno and z.cno=y.cno))
--select sname from student where sno in(select sno from score group by sno having count(*)= (select count(*) from course))
数据库简单练习 建表+select的更多相关文章
- mysql数据库(一):建表与新增数据
一. 学习目标 理解什么是数据库,什么是表 怎样创建数据库和表(create) 怎样往表里插入数据(insert) 怎样修改表里的数据(update) 怎样删除数据库,表以及数据(delete) 二. ...
- 0420-mysql命令(数据库操作层级,建表,对表的操作)
注意事项: 符号必须为英文. 数据库操作层级: 建表大全: #新建表zuoye1:drop table if exists zuoye1;create table zuoye1( id int ...
- JavaFX程序初次运行创建数据库并执行建表SQL
在我的第一个JavaFX程序完成安装的时候才突然发现,不能要用这个软件还要手动执行Sql来建表吧? 于是我的想法是在Main程序中执行时检测数据库连接状况,如果没有检测到数据库或者连接异常,那么出现错 ...
- Mysql数据库常规操作(建表、查询)
一.表单操作 1-1.创建表 create table tb_name( id in primary key auto_increment); 1-2.查看表 desc table_name; ...
- SQL数据库各种查询建表插入集合-待续持续更新
创建表 drop table student; DROP table Course; DROP table sc; CREATE TABLE student ( sid integer PRIMARY ...
- java中用activiti插件连接mysql数据库,自动建表过程中,在配置mysql架包路径“org.activiti.engine.ActivitiException: couldn't check if tables “
java中用activiti插件连接mysql数据库,出现错误: org.activiti.engine.ActivitiException: couldn't check if tables are ...
- 使用Mysql 5.5数据库Hibernate自动建表创建表出错table doesn't exist
在mysql 5.0版本以后不支持 type=InnoDB 关键字,需要使用 engine=InnoDB 配置文件方言改成如下即可 <property name="dialect&qu ...
- mysql建表设置两个默认CURRENT_TIMESTAMP的技巧
转载:http://blog.163.com/user_zhaopeng/blog/static/166022708201252323942430/ 业务场景: 例如用户表,我们需要建一个字段是创 ...
- 64、django之模型层(model)--建表、查询、删除基础
要说一个项目最重要的部分是什么那铁定数据了,也就是数据库,这篇就开始带大家走进django关于模型层model的使用,model主要就是操纵数据库不使用sql语句的情况下完成数据库的增删改查.本篇仅带 ...
随机推荐
- bzoj4807 車
题目大意: Description 众所周知,車是中国象棋中最厉害的一子之一,它能吃到同一行或同一列中的其他棋子.車跟車显然不能在一起打 起来,于是rly一天又借来了许多许多的車在棋盘上摆了起来……他 ...
- Mac 显示sudo: pip: command not found
Mac显示sudo: pip: command not found mac在安装完pip模块后,使用pip命令会提示sudo: pip: command not found moyanzhudeMac ...
- java开发爬虫Deno
java开发爬虫Deno 身为一个程序员不会两三手爬虫怎么能在行业里立足啊,这是开发中自己写的一个java爬虫的Demo,供大家参考. java爬虫的开发依赖于jsoup.jar 直接上代码 publ ...
- JS中的new操作符
在JS中定义一个构造函数,然后用new操作符构造对象obj,JS代码如下. function Base(){ this.name = "swf"; this.age =20; } ...
- bzoj千题计划255:bzoj3572: [Hnoi2014]世界树
http://www.lydsy.com/JudgeOnline/problem.php?id=3572 明显需要构造虚树 点属于谁管理分三种情况: 1.属于虚树的点 2.在虚树上的边上的点 3.既不 ...
- Splay模板讲解及一些题目
普通平衡树模板以及文艺平衡树模板链接. 简介 平衡二叉树(Balanced Binary Tree)具有以下性质:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二 ...
- 从数据库存储,文件结构谈到B树,散列
昨天俱乐部内部办了一个讲座,关于常规数据库系统实现,听了之后有点混乱,于是花了很多时间特地查了一些资料,基本上自己感觉自己是明白了.特地写下来. 文章开头说明三点, 第一点,本文针对常规数据库,是为了 ...
- [QuickRoR]Ruby on Rails开发环境安装
1.Setup Ruby on Rails2.Test Web App3.Create the First Web App 1.Setup Ruby on Rails1) Download rubyi ...
- JavaScript1.6数组新特性和JQuery的几个工具方法
JavaScript 1.6 引入了几个新的Array 方法,具体的介绍见:New in JavaScript 1.6 .这些方法已经被写进了ECMA262 V5.现代浏览器(IE9/Firefox/ ...
- 工欲善其事必先利其器,用Emmet提高HTML编写速度
HTML代码写起来很费事,因为它的标签多. 一种解决方法是采用模板,在别人写好的骨架内,填入自己的内容.还有一种很炫的方法----简写法. 常用的简写法,目前主要是Emmet和Haml两种.这两种简写 ...