oracle 下樹形結構資料統計
阿新 • • 發佈:2019-01-10
create table czk_dguitest(code varchar(20),name varchar(10),num int)
insert into czk_dguitest values ('01','彩電',null)
insert into czk_dguitest values ('01.01','TCL',null)
insert into czk_dguitest values ('01.01.01','18',10)
insert into czk_dguitest values ('01.01.02','21',20)
insert into czk_dguitest values ('01.01.03','25',30)
insert into czk_dguitest values ('01.02','LG',null)
insert into czk_dguitest values ('01.02.01','18',20)
insert into czk_dguitest values ('01.02.02','25',30)
insert into czk_dguitest values ('01.02.03','29',50)
select * from czk_dguitest
SELECT
A.CODE
,A.name,SUM(decode(B.num,null,0,b.num))
FROM
czk_dguitest A,
czk_dguitest B
WHERE
[color=red] B.code LIKE A.code+'%' [/color]
GROUP BY
A.code,A.name
ORDER BY
A.code
大家看紅色部分腳步怎麼寫才可以通過呢!
insert into czk_dguitest values ('01','彩電',null)
insert into czk_dguitest values ('01.01','TCL',null)
insert into czk_dguitest values ('01.01.01','18',10)
insert into czk_dguitest values ('01.01.02','21',20)
insert into czk_dguitest values ('01.01.03','25',30)
insert into czk_dguitest values ('01.02','LG',null)
insert into czk_dguitest values ('01.02.01','18',20)
insert into czk_dguitest values ('01.02.02','25',30)
insert into czk_dguitest values ('01.02.03','29',50)
select * from czk_dguitest
SELECT
A.CODE
,A.name,SUM(decode(B.num,null,0,b.num))
FROM
czk_dguitest A,
czk_dguitest B
WHERE
[color=red] B.code LIKE A.code+'%' [/color]
GROUP BY
A.code,A.name
ORDER BY
A.code
大家看紅色部分腳步怎麼寫才可以通過呢!