SELECT *
FROM (
	SELECT d.cmsid
		,f.folderpathcomplete
		,d.objectid
		,d.name document_name
		,count(wdp.id) nbr_dps
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%postgr%'
					THEN 'Yes'
				END) AS POSTGRES
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%ms sql%'
					THEN 'Yes'
				END) AS MSSQL
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%tez%'
					THEN 'Yes'
				END) AS NETEZZA
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%access%'
					THEN 'Yes'
				END) AS ACCESS
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%excel%'
					THEN 'Yes'
				END) AS EXCEL
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%hana%'
					THEN 'Yes'
				END) AS HANA
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%tera%'
					THEN 'Yes'
				END) AS TERADATA
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%ora%'
					THEN 'Yes'
				END) AS ORACLE
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%db2%'
					THEN 'Yes'
				END) AS DB2
		,max(CASE 
				WHEN lower(dc14.dbms) LIKE '%400%'
					THEN 'Yes'
				END) AS DB2AS400
		,d.kind
		,d.id document_id
	FROM semanticlayer sl
	INNER JOIN document_datasources ds ON ds.source_id = sl.objectid
	INNER JOIN documents d ON d.id = ds.object_id
		AND d.isdeleted = FALSE
	INNER JOIN v_folders2a f ON f.cmsid = d.cmsid
		AND f.cuid = d.parentfoldercuid
		AND f.isdeleted = FALSE
	INNER JOIN webi1400_documents wd ON wd.cmsid = d.cmsid
		AND wd.objectid = d.objectid
	INNER JOIN webi1400_dataproviders wdp ON wdp.universecuid = sl.cuid
		AND wdp.webi1400document_id = wd.id
	INNER JOIN CONN_SEMANTICLAYER csl ON csl.semanticlayer_id = sl.id
	INNER JOIN data_connections dc ON dc.cmsid = sl.cmsid
		AND dc.objectid = csl.data_connections_id
	INNER JOIN data_connections1400 dc14 ON dc14.cmsid = dc.cmsid
		AND dc14.objectid = dc.objectid
	WHERE sl.isdeleted = FALSE
		AND sl.cmsid = 'YOUR_CMS_ID_HERE' -- right-click in MetaQuery to select this value, or use SELECT DISTINCT CMSID from ROLES to see available values
		AND d.isdeleted = false
	GROUP BY d.cmsid
		,f.folderpathcomplete
		,d.name
		,d.kind
		,d.id
	) AS Z
WHERE NBR_DPS > 0 -- change this to increase "complexity" e.g. "Show me all reports that have morethan 5 dataproviders using MSSQL, Oracle and HANA"
	AND (
		MSSQL = 'Yes'
		OR ORACLE = 'Yes'
		OR POSTGRES = 'Yes'
		)
	AND ACCESS = 'Yes'