SQL une dos consultas simples con count y groupby

hola tengo 2 consultas y quiero unirme pero no sé cómo …

SELECT *, count(*) as invii FROM professionisti JOIN preventivi_invii ON professionisti.email=preventivi_invii.email GROUP BY professionisti.email HAVING invii> 300 SELECT *, count(*) as acquisti FROM professionisti JOIN contatti_acquistati ON professionisti.email=contatti_acquistati.email GROUP BY professionisti.email HAVING acquisti> 5 

el problema para mí es el conteo múltiple y el grupo por la misma columna. Gracias

¿Qué tal la consulta a continuación? Simplemente cambiaría la cláusula WHERE para satisfacer sus necesidades.

Ejemplo de SQL Fiddle :

 SELECT * FROM ( SELECT p.email, CASE WHEN ISNULL(m1.invii) THEN 0 ELSE m1.invii END AS invii, CASE WHEN ISNULL(m2.acquisti) THEN 0 ELSE m2.acquisti END AS acquisti FROM professionisti p LEFT JOIN ( SELECT pp.email, COUNT(*) AS invii FROM preventivi_invii pp GROUP BY pp.email ) AS m1 ON p.email = m1.email LEFT JOIN ( SELECT c.email, COUNT(*) AS acquisti FROM contatti_acquistati c GROUP BY c.email ) AS m2 ON p.email = m2.email ) AS mm WHERE mm.invii = 0 OR mm.acquisti = 0; 

O podrías usar:

 SELECT * FROM ( SELECT p.email, ( SELECT CASE WHEN ISNULL(COUNT(*)) THEN 0 ELSE COUNT(*) END FROM preventivi_invii pp WHERE pp.email = p.email ) AS invii, ( SELECT CASE WHEN ISNULL(COUNT(*)) THEN 0 ELSE COUNT(*) END FROM contatti_acquistati c WHERE c.email = p.email ) AS acquisti FROM professionisti p ) AS mm WHERE mm.invii = 0 OR mm.acquisti = 0