别问,学就对了

视图 (view):视图的作用就是当一个表中的数据并不想对成员全部开放,只针对不同权限的用户开放不同的数据部分,同子图一样,但是子图的修改,父图并不受影响,而视图,解决了这一问题依赖于某表创建一个视图create view empviewas select employee_id id, last_name name, salary salfrom employeeswhere department_id = 80更改数据update empviewset salary = 10000where employee_id = 179

(于此同时,employees表中的工号179的人的salary也是10000)

删除数据(注意约束条件,如果有子记录就无法删除)delete from empview where employee_id = 176;基于多个已存在的表创建视图create view empview2asselect employee_id id , last_name name, salary sal ,department_name from employees e, departments dwhere e.department_id = d.department_id

修改视图create or replace

create or replace view empview2asselect employee_id id , last_name namefrom employees e, departments dwhere e.department_id = d.department_id

这样就会将原来的视图覆盖

屏蔽DML操作create or replace view empview2asselect employee_id id , last_name namefrom employees e, departments dwhere e.department_id = d.department_idwith read only

这个视图只能读,不能改

复杂视图(有组函数,视图一个或多个)create or replace view empview3asselect department_name dept_name,avg(salary) avg_salfrom employees e , departments dwhere e.department_id = d.department_idgroup by department_name不存在的列必须起一个别名,且在复杂视图中是不可以使用DML的增删改操作,比如说要改一个平均值,改了之后,那么原来的众多salary改哪个才能使平均值变为更改后的。简单视图运行增删改,复杂视图由于使用了组函数,不允许增删改删除视图 drop view empview3;Top-N分析top表示前多少个,N是代表多少,比如2014最好看的前10名电影,Top-10比如百度搜索信息,第一页显示前10个,第二页10-20的数据。从表中获取工资前10的员工id,姓名(rownum(伪列)当前表对应的行号)select rownum, employee_id , last_name , salaryfrom (select employee_id , last_name , salaryfrom employeesorder by salary desc)where rownum <= 10这样可以获取前10名,但是麻烦但是针对于rownum只能是<= 或 < ,而 = ,> ,>=将不能返回任何数据

查询工资排名40-50名之间

给前一个rownum起一个别名,,那么rn在外面这个表中,就不是伪列,那么就可以用>,>=,=select rn , employee_id , last_name , salaryfrom (select rownum, employee_id , last_name , salaryfrom (select employee_id , last_name , salaryfrom employeesorder by salary desc))where rn > 40 and rn <50这样就实现了类似于百度的分页的效果

有的旅行是为了拓宽眼界,浏览风景名胜。

别问,学就对了

相关文章:

你感兴趣的文章:

标签云: