select ci_id, wm_concat(name)
from (select ci_id, decode(instr(stu_ids, stu_id), 0, '', stu_name) name
from (select c.ci_id, c.stu_ids, s.stu_id, s.stu_name
from pm_ci c, pm_stu s))
group by ci_id;
from (select ci_id, decode(instr(stu_ids, stu_id), 0, '', stu_name) name
from (select c.ci_id, c.stu_ids, s.stu_id, s.stu_name
from pm_ci c, pm_stu s))
group by ci_id;
6分鐘這位置解釋rownum,被強行帶偏了。在我11g里,rownum始終都是偽列。參考以下兩個sql
select rownum,sal from emp order by sal desc;
select rownum,sal from(
select rownum,sal from emp order by sal desc
);
兩個sql執行的結果是一樣的,除了rownum列。
第一條sql的rownum是亂序的,第二條是有序的。但其他列順序是一樣的。倘若第二條sql中的子查詢的rownum在主查詢中真的變成了實列,那么兩個查詢中的rownum列應該相同。
select rownum,sal from emp order by sal desc;
select rownum,sal from(
select rownum,sal from emp order by sal desc
);
兩個sql執行的結果是一樣的,除了rownum列。
第一條sql的rownum是亂序的,第二條是有序的。但其他列順序是一樣的。倘若第二條sql中的子查詢的rownum在主查詢中真的變成了實列,那么兩個查詢中的rownum列應該相同。
-- 設置列寬
col ci_id format a20
col stu_names format a20
--行顯示設置
set linesize 100
-- sql查詢語句
select pc.ci_id ci_id,wm_concat(pt.stu_name) stu_names
from pm_ci pc,pm_stu pt
where instr(pc.stu_ids,pt.stu_id)>0
group by pc.ci_id;
col ci_id format a20
col stu_names format a20
--行顯示設置
set linesize 100
-- sql查詢語句
select pc.ci_id ci_id,wm_concat(pt.stu_name) stu_names
from pm_ci pc,pm_stu pt
where instr(pc.stu_ids,pt.stu_id)>0
group by pc.ci_id;
select *
from (select rownum rm,e1.* from (select * from emp order by sal desc) e1 where rownum<=8) e2
where rm>=5;
from (select rownum rm,e1.* from (select * from emp order by sal desc) e1 where rownum<=8) e2
where rm>=5;
剛開始有點不理解,覺得這種求解應該先通過分組函數和avg函數求出每個部門的平均值,再多表查詢設定條件合并兩張表。現在學習了新方法!省力多了!
2020-02-21