数据库学习之二

先按照e.division_id排序,再按照e.salary排序;

select * from employees2 e order by e.division_id asc ,e.salary desc;

rownum的用法:对函数进行排序

思路:先将表中所有人的薪水按照降序排序,将排序后的表当作一个新表,别名为a,在选取a表中薪水排名前5的;

注:由于将此表重新当成了新表,所以前面写列名开头需用a.开头

max函数:求最大值

select * from employees2 e where e.salary=(select max(e.salary) from employees2 e)

insert into 插入语句的运用

注:

1、可通过单击鼠标右键点击describe查看表格各个元素的属性;

2、insert into 插入会受到主键约束、非空约束、外键约束、类型匹配,可通过点击foreign keys查看产品表的外键表;

3、提交命令commit,添加的数据只有点击提交按钮后才能保存在表中;回滚:rollback,提交后回滚无效;

4、在values后面的口号里如果使用&+名称,可运行后再自行输入值;

create函数:创建表格函数 、 delete函数:删除函数的使用 、update函数:更新函数

 

 

    

将firstname和lastname连接起来组成fullname,小于50周岁的

select c.first_name,c.last_name,
trunc(months_between(sysdate,c.dob)/12) age
from customers c where trunc(months_between(sysdate,c.dob)/12)
<=50

trunc函数不保留小数点

select concat(concat(c.first_name,' '),c.last_name) fullname,
trunc(months_between(sysdate,c.dob)/12) age
from customers c where trunc(months_between(sysdate,c.dob)/12)
<=50;

select c.first_name,c.last_name,
round ((months_between(sysdate,c.dob)/12),1) age
from customers c

round函数 可选择保留小数点后几位小数

 

各个部门各个职位大于整个公司工资平均值显示出来

select e.division_id,e.job_id,avg(e.salary) from
employees2 e group by e.division_id,e.job_id
having avg(e.salary)>(select avg(e.salary)from employees2 e)

posted @ 2016-05-21 17:26  Melody霖  阅读(192)  评论(0编辑  收藏  举报