Context:
I am looking to figure out how to create a combined sql statement that would sum the size and count the number of files in a particular volume path saved in the file
column of a table. The path is an absolute path from the root volume all the way up to the file location. some volume paths have upwards of 400+ characters includes white space and special characters. I an looking to get a list size and file count based on the list of folders in the target location. I am able to extract the file list or sum & count all files in the target folder but not for each of the sub folder in one more level deeper. I was working with a flat file that had this information in it per line and I used php to import it into the MariaDB so we can run queries and report on the given information.
select distinct left(replace(file, '/volume/path/to/target/folder/', '' ),locate("/",replace(file, '/volume/path/to/target/folder/', '' ))) from FileList
Output:
These/
are/
the/
folders/
are/
looking/
for/
whey trying to group by:
select left(replace(file, '/volume/path/to/target/folder/', '' ),locate("/",replace(file, '/volume/path/to/target/folder/', '' ))) as 'folder', sum(realsize), count(file) from FileList where file like '/volume/path/to/target/folder%' group by 'folder'
output:
folder, sum(realsize), count(file)
<blank>, 127534970, 2340239024
Trying a subquery:
select
left(replace(file, '/volume/path/to/target/folder/', '' ),locate("/",replace(file, '/volume/path/to/target/folder/', '' ))) as 'folder'
count(file),
sum(realsize)
From
FileList
Where
folder in (select distinct left(replace(file, '/volume/path/to/target/folder/', '' ),locate("/",replace(file, '/volume/path/to/target/folder/', '' ))) from FileList)
output:
folder, sum, count
*NULL*,127534970,*NULL*
Question:
What am doing wrong with combining to get the output I am looking for?
expected output:
(random number to simulate output)
folder, sum, count
These/, 1245, 234
are/ , 2345, 345
the/ , 8675, 456
folders/, 345, 34
are/ , 9876, 123
looking/, 456, 2
for/, 2346890, 987