有三張表。
a01人員串列 (人員資訊)
b01單位串列 (單位的一些資訊)
c01工資串列。(工資的一些資訊)
現在我查詢出這種效果圖

當前查出的是所有子單位的資料,每個子單位是有上級單位的,
比如 01單位有下屬單位的,分別是011單位和012單位.
02單位的下屬單位是 022單位和023單位的
查詢人數的時候都是
Select count(*) from a01,b01 where a01.單位代碼=b01.單位代碼
現在我想要寫一個視圖。

額,不會寫- -,目前視圖是這樣的:
CREATE OR REPLACE VIEW VIEW_A01_B01_C01 AS
Select 單位名稱,count(*) as 人數,工資
From a01,b01,c01
Where a01.id=c01.id and a01.單位代碼=b01.單位代碼
group by b01.單位名稱,c01.工資
order by 單位代碼;?
一下午也沒有解決好。特此求助,積分不多。只能希望有好人幫助一下
uj5u.com熱心網友回復:
with t1 as
(select '1' id ,'部門1' name,'0' pid from dual
union all
select '2' id ,'部門11' name,'1' pid from dual
union all
select '3' id ,'部門12' name,'1' pid from dual
union all
select '4' id ,'部門2' name,'0' pid from dual
union all
select '5' id ,'部門21' name,'4' pid from dual
union all
select '6' id ,'部門22' name,'5' pid from dual
union all
select '7' id ,'部門23' name,'5' pid from dual
)
select id,name from t1
start with pid='0'
connect by prior id= pid
然后再根據部門ID,做人數和工資數的匯總
uj5u.com熱心網友回復:
with t as(select '01' id ,2 pcnt,7000 sal from dual
union all
select '011' id ,1,2000 from dual
union all
select '012' id ,2,4500 from dual
union all
select '02' id ,4,13040 from dual
union all
select '021' id ,3,7600 from dual
union all
select '022' id ,2,5500 from dual
)
select id,substr(id,1,2) a,sum(pcnt),sum(sal),grouping_id(substr(id,1,2),id) gid,
decode(grouping_id(substr(id,1,2),id),0,id,1,substr(id,1,2)||'及以下匯總',3,'所有匯總',null) sid
from t group by rollup(substr(id,1,2),id)
/*having grouping_id(substr(id,1,2),id)<>'3'*/
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
SQL> select deptno,job,sal from emp;DEPTNO JOB SAL
---------- --------- ----------
20 CLERK 800
30 SALESMAN 1600
30 SALESMAN 1250
20 MANAGER 2975
30 SALESMAN 1250
30 MANAGER 2850
10 MANAGER 2450
20 ANALYST 3000
10 PRESIDENT 5000
30 SALESMAN 1500
20 CLERK 1100
30 CLERK 950
20 ANALYST 3000
10 CLERK 1300
SQL> with tt as(
2 select deptno,count(job) 作業數,sum(sal) 部門工資 from emp group by cube(deptno,job))
3 select * from tt where deptno is not null order by deptno,作業數 desc;
DEPTNO 作業數 部門工資
---------- ---------- ----------
10 3 8750
10 1 2450
10 1 5000
10 1 1300
20 5 10875
20 2 1900
20 2 6000
20 1 2975
30 6 9400
30 4 5600
30 1 950
30 1 2850
已選擇12行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/107627.html
標籤:基礎和管理
