With Reference to one of the question answer before, Getting counts/totals at each level of a hierarchical query using CONNECT BY
DIRS
====
DIR_ID
PARENT_DIR_ID
DIR_NAME
FILES
=====
FILE_ID
FILE_NAME
DIR_ID
FILE_SIZE
If DIRS contains:
DIR_ID PARENT_DIR_ID DIR_NAME
====== ============= ========
1 ROOT
2 1 DIR1_1
3 1 DIR1_2
4 2 DIR2_1
5 2 DIR2_2
Out Out is shown below.
FILE_ID FILE_NAME DIR_ID FILE_SIZE
======= ========= ====== =========
1 test1.txt 5 100
2 test2.txt 5 200
3 test5.txt 5 50
4 test3.txt 3 300
5 test4.txt 3 300
6 test6.txt 4 100
I want a query that returns the path along with the number of files in or below each node in the hierarchy. Basically a rollup of the number of files. So the query result would look something like:
Path File_Count File_Size
===== =========== --------
/ROOT 6 1050
/ROOT/DIR1_1 4 450
/ROOT/DIR1_1/DIR2_1 1 100
/ROOT/DIR1_1/DIR2_2 3 350
/ROOT/DIR1_2 2 600
1 select sys_connect_by_path(dp.dir_name, '/') path
2 ,(select count(file_id)
3 from dirs dc
4 ,files f
5 where f.dir_id(+) = dc.dir_id
6 connect by prior dc.dir_id = dc.parent_dir_id
7 start with dc.dir_id = dp.dir_id
8 ) count
9 from dirs dp
10 connect by prior dp.dir_id = dp.parent_dir_id
11* start with dp.parent_dir_id is null
How can i also get count of File size column next to size column.
This Query is doing fine except sum of the count of file size.
(select count(file_id)
from dirs dc
,files f
where f.dir_id(+) = dc.dir_id
connect by prior dc.dir_id = dc.parent_dir_id
start with dc.dir_id = dp.dir_id
) count,
(select sum(file_size)
from dirs dc
,files f
where f.dir_id(+) = dc.dir_id
connect by prior dc.dir_id = dc.parent_dir_id
start with dc.dir_id = dp.dir_id
) size
from dirs dp
connect by prior dp.dir_id = dp.parent_dir_id
start with dp.parent_dir_id is null
I modified the query to get size of files of each level but no success. Any idea what is missing?
All i need is the count of the File_Size column as shown above.