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;
2020-06-16
select pc.ci_id,wm_cancat(ps.stu_name) stu names from pm_ci pc ,pm_stu ps where instr( pc.stu_ids,ps.stu_id)>0
group by pc.ci_id;
group by pc.ci_id;
2020-05-11
6分鐘這位置解釋rownum,被強(qiáng)行帶偏了。在我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執(zhí)行的結(jié)果是一樣的,除了rownum列。
第一條sql的rownum是亂序的,第二條是有序的。但其他列順序是一樣的。倘若第二條sql中的子查詢的rownum在主查詢中真的變成了實(shí)列,那么兩個查詢中的rownum列應(yīng)該相同。
select rownum,sal from emp order by sal desc;
select rownum,sal from(
select rownum,sal from emp order by sal desc
);
兩個sql執(zhí)行的結(jié)果是一樣的,除了rownum列。
第一條sql的rownum是亂序的,第二條是有序的。但其他列順序是一樣的。倘若第二條sql中的子查詢的rownum在主查詢中真的變成了實(shí)列,那么兩個查詢中的rownum列應(yīng)該相同。
-- 設(shè)置列寬
col ci_id format a20
col stu_names format a20
--行顯示設(shè)置
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
--行顯示設(shè)置
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;
2020-02-28
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;
剛開始有點(diǎn)不理解,覺得這種求解應(yīng)該先通過分組函數(shù)和avg函數(shù)求出每個部門的平均值,再多表查詢設(shè)定條件合并兩張表?,F(xiàn)在學(xué)習(xí)了新方法!省力多了!
2020-02-21
select a.ci_id,wm_concat(b.stu_name)
from pm_ci a,pm_stu b
where instr(a.stu_ids,b.stu_id) > 0
group by a.ci_id
from pm_ci a,pm_stu b
where instr(a.stu_ids,b.stu_id) > 0
group by a.ci_id
2020-02-21