Hola a todos, necesito hacer una consulta y ante la duda lo he hecho de dos maneras diferentes una con select anidados y otra con Join. El problema es que me dan dos cifras totalmente diferentes y no encuentro cual puede ser el error, para mi son las dos iguales pero hechas de diferente manera, a ver si alguien me puede ayudar. Aqui dejo las dos consultas:
SELECT a.id_cgh, a.add_number, a.add_floor, COUNT(*), s.id_address, count(s.id_address) cont
FROM gccom_supply s
JOIN gccom_address a
ON s.id_address = a.id_address
AND a.id_cgh is NOT null
JOIN gccom_sector_supply ss
ON s.id_supply = ss.id_supply
JOIN gccom_contracted_service cs
ON ss.id_sector_supply = cs.id_sector_supply
WHERE cs.status = 'ESTSC00002'
GROUP BY a.id_cgh, a.add_number, a.add_floor, s.id_address
HAVING COUNT(s.id_address) > 1;
select count(*),gs.id_address
from gccom_supply gs
where gs.id_address in (select ga.id_address from gccom_address ga
where ga.id_cgh is not null)
and GS.ID_SUPPLY in
(select gss.id_supply
from gccom_sector_supply gss
where GSS.ID_SECTOR_SUPPLY in
(select gcs.id_sector_supply
from gccom_contracted_service gcs
where gcs.status = 'ESTSC00002'
)
)
group by gs.id_address
having count(*) > 1;
Gracias a todos, un saludo