其實這兩天還是都在講基本的語法
内容其實不多 我就不在文章中列出了
可以點下面的筆記連接進行察看
SQL這東西大同小異
但是 精通Oracle比精通java php會工資高很多
原因大家可以自行推度娘
順便放上兩天的示例題目供參考
1.创建表 student_yourname
里面有这么些属性
学号 id number(8)
名字 name varchar2(20)
班级号 class_id varchar2(12)
喜欢的人id lover_id varcha(8)
create table student
(id number(8),
name varchar2(20),
class_id varchar2(12),
lover_id varchar2(8),
)
2.观察建好的表的表头与类型;观察表的内容。请问你是否记住了这2个命令
3.插入如下数据:
1,Tom,jsd120201,4
2,Abel,jsd120201,null
3,Ben,jsd120202,4
4,Lucy,jsd120203,1
5,Lily,jsd120203,3
6,Carl,jsd120203,5
7,Tom,jsd120203,4
insert into student values(1,’Tom’, ‘jsd120201′,’4′);
insert into student values(2,’Abel’,’jsd120201′,null);
insert into student values(3,’Ben’,’jsd120202′,4);
insert into student values(4,’Lucy’,’jsd120203′,1);
insert into student values(5,’Lily’,’jsd120203′,3);
insert into student values(6,’Carl’,’jsd120203′,5);
insert into student values(7,’Tom’,’jsd120203′,4);
4.查询出jsd120203班的学生信息;
select * from student where class_id = ‘jsd120203’;
5.查询出所有的人名,不可重复;
select distinct name from student;
6.查询出如下人得信息,学号为2,3,4;分别使用between and;=any;>,and,<3种写法 select * from student where id between 2 and 4; select * from student where id =any(2,3,4); select * from student where id <5 and id>1 ;
7.查询出所有jsd120202,jsd120203班学生的信息;请分别使用in;not in 2种写法;
select * from student where class_id in(‘jsd120202′,’jsd120203’);
select * from student where class_id not in (‘jsd120201’);
8.查找出所有名字为4个字母的学员的信息
select * from student where name like ‘____’;
9.查询出所有有心仪对象的人,并显示出心仪对象的班级和姓名,若无,则显示为love self;
select id , name , class_id,
nvl((select name from student s2 where s2.id =s1.lover_id ),’self’) lover
from student s1;
1,Tom,jsd120201,love lucy
10.查找出所有相互爱着的学员的信息
select id, name peopleInLove
from student s1
where s1.id =
(select lover_id from student s2 where s2.id = s1.lover_id );
=====================================================
day02 作业
empno ename job salary bonus hiredate mgr deptno
1.写出select,from,where,group by,having,order by执行的顺序;
写出where 后面不能直接跟什么?
from ->where->group by -> having -> select -> order by
不能直接跟组函数,组标识
2.查出与入职时间最早(想想是最大还是最小)的人相同职位的人的平均的bonus;
select avg(bonus) from emp
where job =
(select job from emp
where hiredate =
(select min(hiredate) from emp));
3.查出所有总人数超过数据库中没有拿到bonus人数数量的部门;
select deptno from emp having count(deptno)>
(select count(*)-count(bonus) from emp)
group by deptno;
4.查出所有年薪比经理最低工资高但不是经理的人的信息,按年薪从小到大排列;
select * from emp
where salary > (select min(salary) from emp where job=’manager’)
and job <>‘manager’
order by salary desc;
5.查出所有部门平均工资比10部门最低工资要高的部门以及其平均工资,要求四舍五入保留1位小数;
select deptno ,round(avg(salary),1) from emp
having avg(salary)>
(select min(salary) from emp where deptno=10)
group by deptno;
以下是課堂内容
OracleDB_Day01
OracleDB_Day02