-2

I have a table like below:

DirectoryName    FileName
    A               Ab.pdf
    B               bc.mp3
    C               cd.doc
    A               de.pdf
    F               fg.pdf
    A               kl.pdf

The output should be like this:

Directory 
 A - 3
 B - 1
 C - 1
 F - 1

And same with FileName.

Thanks

Sam
  • 11
  • 5

1 Answers1

1

Simple Solution is :

select distinct DirectoryName, count(FileName) 
from tableName group by DirectoryName

Or you can use partition by over DirectoryName

select distinct DirectoryName, COUNT(FileName) 
over(Partition by DirectoryName) 
Count from tableName

Hope this will work for you.

Mr.Bhanushali
  • 126
  • 12