        end,
        taxon_ref,
        taxon_level_ref,
+       lithology_ref,
        type
 )
 select "Branch", 
        "Department", 
        "Group", 
        continent, 
-       (select count(distinct taxon_ref) 
-        from specimens_data as sub_specimen_data
-        where sub_specimen_data.taxon_level_ref >= 48 
-          and sub_specimen_data.type != 'specimen'
-          and sub_specimen_data."Group" = main_specimen_data."Group"
-          and sub_specimen_data.continent = main_specimen_data.continent
-       ) as "Type Taxa",
+       case 
+         when "Branch" = 'MIN' then
+           (
+             select count(distinct lithology_ref) 
+             from specimens_data as sub_specimen_data
+             where sub_specimen_data.type != 'specimen'
+               and sub_specimen_data."Branch" = main_specimen_data."Branch"
+               and sub_specimen_data."Department" = main_specimen_data."Department"
+               and sub_specimen_data."Group" = main_specimen_data."Group"
+               and sub_specimen_data.continent = main_specimen_data.continent
+           )
+         else
+           (
+             select count(distinct taxon_ref) 
+             from specimens_data as sub_specimen_data
+             where sub_specimen_data.taxon_level_ref >= 48 
+               and sub_specimen_data.type != 'specimen'
+               and sub_specimen_data."Branch" = main_specimen_data."Branch"
+               and sub_specimen_data."Department" = main_specimen_data."Department"
+               and sub_specimen_data."Group" = main_specimen_data."Group"
+               and sub_specimen_data.continent = main_specimen_data.continent
+           ) 
+       end as "Type Taxa",
        coalesce((select sum(specimen_count_maximum) 
         from specimens_data as sub_specimen_data
         where sub_specimen_data.type != 'specimen'
+          and sub_specimen_data."Branch" = main_specimen_data."Branch"
+          and sub_specimen_data."Department" = main_specimen_data."Department"
           and sub_specimen_data."Group" = main_specimen_data."Group"
           and sub_specimen_data.continent = main_specimen_data.continent
        ),0) as "Type",
-       count(distinct taxon_ref) as "Specimen Taxa"
+       case 
+         when "Branch" = 'MIN' then
+           count(distinct lithology_ref)
+         else
+           count(distinct taxon_ref) 
+       end as "Specimen Taxa"
 from specimens_data as main_specimen_data
 group by "Branch", "Department", "Group", continent
 order by "Branch", "Department", "Group", continent

	      strpos(taxon_path, '/19/') != 0 or
	      strpos(taxon_path, '/81/') != 0 or
	      strpos(taxon_path, '/83/') != 0 or
	      strpos(taxon_path, '/90/') != 0 
	     ) and 
	     (collection_ref = 2 or collection_path like '/2/%') 
          then
          'IZ'
         else
           'Other'
       end as "Department",

       end as continent,
       taxon_ref,
       taxon_level_ref,
       lithology_ref,
       type,
       sum(specimen_count_max) as specimen_count_maximum
from specimens left join gtu_infos on specimens.gtu_ref = gtu_infos.gtu_ref
