小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

有關數據庫的 基本操作

 心不留意外塵 2016-07-17
http://blog.csdn.net/wuyinxian/article/details/7393398
2012

----學習 數據庫


-- 左右連接
select * from emp ,dept where emp.deptno (+)= dept.deptno and dept.deptno = 40


-- 1999 笛卡爾集  自然連接
select * from emp ,dept
select * from emp natural join dept
---指定消除笛卡爾集
select * from emp join dept using (deptno)




--- 分組查詢之后,只能出現改字段和統(tǒng)計函數, nal( , 0) ,函數是用來設定default的
select  dept.dname ,count(dept.deptno) ,nvl(sum(emp.sal),0)
  from emp, dept
 where emp.deptno (+)= dept.deptno --and avg(emp.sal) >2000
  group by dept.dname
  having avg(emp.sal) >2000


--- 測試
select (select dept.deptno from dept) dno ,* from emp where dno = emp.deptno where job <> 'SALESMAN' group by job order by sums ASC
select * from emp order by sal


--- /////////////驗證 語句  start
--- 驗證子查詢 在where 中主要返回 單行單列 ,多行單列,單行多列
select * from emp where sal > (select avg (sal)  from emp )
--- 驗證子查詢 在where 中主要返回 單行多列
select * from emp where (job ,sal) =(select job ,sal from emp where emp.ename = 'SMITH')
--- 驗證 子查詢總 在where 中返回 多行單列
--- ;有關 in 的操作
---注意如果 not in  中有null 那么不會有任何結果返回
select * from emp where sal in (select sal from emp where emp.ename <> 'SMITH')


-- 有關 any  操作  = 任何一個  > 比最小的要大,  < 比最大的要小
select * from emp where sal >any (select sal from emp where emp.sal > 2000)


-- 有關 all  操作  = (如果是多行,則不會有結果)  > 比最大的要大,  < 比最小的要小
select * from emp where sal =all (select sal from emp where  emp.sal > 2000 )


--- 驗證子查詢 在where 中主要返回 單行單列 ,多行單列,單行多列
select * from emp natural  join (select sal,job from emp where emp.ename <> 'SMITH') tmp




------ /////////////驗證 語句  end




---下面考慮的是 在什么時候用子查詢,這里說的是有負責的統(tǒng)計一般是會放在子查詢中
select dept.deptno, dept.dname, dept.loc, tmp.sals
  from dept,
       (select deptno, sum(sal) sals
          from emp
         where emp.ename <> 'SMITH'
         group by deptno) tmp
 where tmp.deptno = dept.deptno
 
 ---數據遷移
create table tmpemp as select * from emp where emp.ename = 'SMITH'




 --數據跟新
insert into tmpemp
  select 2999 + 1, ename, job, mgr, sysdate, 3000, comm, deptno
    from emp
   where emp.sal < 2000
   
select * from tmpemp
commit


-- 刪除數據 truncate drop delete
delete from tmpemp where tmpemp.empno = 2999
commit


--  TRUNCATE TABLE name [DROP/REUSE STORAGE]
--  DROP STORAGE:顯式指明釋放數據表和索引的空間
 --  REUSE STORAGE:顯式指明不釋放數據表和索引的空間
truncate table tmpemp drop storage ---truncate  不能加where條件 如: where tmpemp.empno = 3000     

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多