Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9164

How to Join Sub-Queries?

$
0
0

Hi Experts

 

I have a problem with the following query, if I execute only "SISTEMA" sub-query it take 3 seconds and return 7.8 Million records , if I execute "entidad" sub.query it take another 3 seconds and return 15.8 million records, but when I join those two sub-queries it take about 1 minute, any idea of how improve that

 

 

SELECT *

from

(

SELECT      deo_cod,

                   MAX(cla_ncod) AS CLASIF,

                        COUNT(DISTINCT ENT_NCOD) AS NumeroEntidades

FROM        "_SYS_BIC"."sbs/AN_DETALLE"

WHERE       per_ncod = '20130131' 

GROUP BY  deo_cod 

) SISTEMA ,

(

SELECT      deo_cod,

                  ent_cdec,

                  cla_ncod

FROM        "_SYS_BIC"."sbs/AN_DETALLE"

WHERE       per_ncod = '20130131'

GROUP BY deo_cod, ent_cdec, cla_ncod

) entidad

WHERE sistema.deo_cod = entidad.deo_cod  

 

Regards

 

Cristian


Viewing all articles
Browse latest Browse all 9164

Trending Articles