91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

標量子查詢

發布時間:2020-06-26 22:35:36 來源:網絡 閱讀:451 作者:llc018198 欄目:關系型數據庫

--標量子查詢
select e.empno, e.ename, e.sal, e.deptno,
       (select d.dname from dept d where e.deptno = d.deptno)as dname
  from emp e
--插入一條數據
insert into emp(empno,deptno) values(9999,null)--返回結果15條記錄
--改成left join(hash outer)
select e.empno, e.ename, e.sal, e.deptno,d.dname
  from emp e
  left join dept d
    on (e.deptno = d.deptno)
--NL outer
select /*+ use_nl(e,d) */e.empno, e.ename, e.sal, e.deptno,d.dname
  from emp e
  left join dept d
    on (e.deptno = d.deptno)
/*Note:修改后plan一般有outer字樣,如果沒有,注意是否改錯。*/

--用left join 優化標量子查詢之聚合改寫
select dp.department_id, dp.department_name, dp.location_id,
       nvl((select sum(em.salary)
              from hr.employees em
             where em.department_id = dp.department_id),
            0) as sum_dept_salary
  from hr.departments dp

--錯誤寫法
select dp.department_id, dp.department_name, dp.location_id,
       nvl(sum(em.salary), 0) as sum_sal
  from hr.departments dp
  left join hr.employees em
    on dp.department_id = em.department_id
    
--原標量子查詢改寫為:

select em.department_id, sum(em.salary) as sum_sal
  from hr.employees em
 group by em.department_id
 
 --左聯改寫后的內聯視圖
  select dp.department_id, dp.department_name, dp.location_id,
         nvl(sum(e.sum_sal), 0) as sum_sal
    from hr.departments dp
    left join (select e.department_id, sum(e.salary) as sum_sal
                 from hr.employees e
                group by e.department_id) e
      on (dp.department_id = e.department_id)
   group by dp.department_id, dp.department_name, dp.location_id
--
create table dept2 as select * from scott.dept;
insert into dept2  select * from scott.dept where deptno=10

select t1.job, t1.deptno,
       (select distinct dname from dept2 b where b.deptno = t1.deptno) as dname
  from scott.emp t1
 order by 1, 2, 3
--以下改寫結果變了
select distinct t1.job, b.deptno, b.dname
  from scott.emp t1
  left join dept2 b
    on t1.deptno = b.deptno
--正確改寫
select t1.job, t1.deptno, f.dname
  from scott.emp t1
  left join (select b.deptno, b.dname
               from dept2 b
              group by b.deptno, b.dname) f
    on (f.deptno = t1.deptno)

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宁德市| 南丹县| 钟祥市| 东台市| 红安县| 兴宁市| 申扎县| 尖扎县| 荔波县| 旺苍县| 黄梅县| 旌德县| 长丰县| 邢台市| 德令哈市| 峨眉山市| 册亨县| 常州市| 仁怀市| 海盐县| 普洱| 淮北市| 本溪| 竹山县| 遵义县| 鄂伦春自治旗| 青龙| 安国市| 怀仁县| 新蔡县| 西宁市| 时尚| 乌审旗| 海城市| 利辛县| 东辽县| 汤原县| 冀州市| 澜沧| 南木林县| 武威市|