Ver Mensaje Individual
  #5 (permalink)  
Antiguo 20/08/2014, 09:33
Avatar de Maverick2786
Maverick2786
 
Fecha de Ingreso: diciembre-2012
Mensajes: 107
Antigüedad: 11 años, 5 meses
Puntos: 1
Respuesta: Union de las 2 consultas

Si , llevas razon y gracias por la respuesta , lo logre solucionar y me quedo asi:
Código MySQL:
Ver original
  1. select  1 as sexo,'01' as edad,1 as estado ,count(contax) as pama, (select count(contaa) st
  2.         from
  3.             (select distinct concat(nro_identificacion,tipo_identificacion) as contaa
  4.             from formulario_f5 as f5
  5.             where en_tarv = 2
  6.             and fecha_atencion between '2000-01-01' and '2014-08-19'
  7.             and concat(nro_identificacion,tipo_identificacion) in
  8.                 (select distinct concat(nro_identificacion,tipo_identificacion)
  9.                 from formulario_f1
  10.                 where fecha_atencion between '2000-01-01' and '2014-08-19'
  11.                 and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  12.                 and sexo=1
  13.                 and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
  14.                 )
  15.             group by concat(nro_identificacion,tipo_identificacion)
  16.             having count(concat(nro_identificacion,tipo_identificacion))=1
  17.             ) as canttarv) as st, (select count(l) as l
  18.             from
  19.                 (select distinct concat(nro_identificacion,tipo_identificacion) as l
  20.                 from formulario_f5 as f5
  21.                 where en_tarv = 1
  22.                 and fecha_atencion between '2000-01-01' and '2014-08-19'
  23.                 and concat(f5.nro_identificacion,f5.tipo_identificacion) in
  24.                     (select distinct concat(f4.nro_identificacion,f4.tipo_identificacion)
  25.                     from formulario_f1 as f1 inner join formulario_f4_f7 as f4
  26.                     on concat(f1.nro_identificacion,f1.tipo_identificacion) = concat(f4.nro_identificacion,f4.tipo_identificacion)
  27.                     where f4.fecha_atencion between '2000-01-01' and '2014-08-19'
  28.                     and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  29.                     and sexo=1
  30.                     and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
  31.                     and f4.tipo_esquema_indicado = 1
  32.                     and  concat(f4.nro_identificacion,f4.tipo_identificacion) not in
  33.                         (select distinct concat(f4.nro_identificacion,f4.tipo_identificacion)
  34.                         from formulario_f1 as f1 inner join formulario_f4_f7 as f4
  35.                         on concat(f1.nro_identificacion,f1.tipo_identificacion) = concat(f4.nro_identificacion,f4.tipo_identificacion)
  36.                         where f4.fecha_atencion between '2000-01-01' and '2014-08-19'
  37.                         and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  38.                         and sexo=1
  39.                         and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
  40.                         and f4.tipo_esquema_indicado in (2,3)
  41.                         )
  42.                     )
  43.                 group by concat(f5.nro_identificacion,f5.tipo_identificacion)
  44.                 having count(concat(f5.nro_identificacion,f5.tipo_identificacion))=1
  45.                 ) as t1) as l, (select count(ll) as ll
  46.             from
  47.                 (select distinct concat(nro_identificacion,tipo_identificacion) as ll
  48.                 from formulario_f5 as f5
  49.                 where en_tarv = 1
  50.                 and fecha_atencion between '2000-01-01' and '2014-08-19'
  51.                 and concat(f5.nro_identificacion,f5.tipo_identificacion) in
  52.                     (select distinct concat(f4.nro_identificacion,f4.tipo_identificacion)
  53.                     from formulario_f1 as f1 inner join formulario_f4_f7 as f4
  54.                     on concat(f1.nro_identificacion,f1.tipo_identificacion) = concat(f4.nro_identificacion,f4.tipo_identificacion)
  55.                     where f4.fecha_atencion between '2000-01-01' and '2014-08-19'
  56.                     and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  57.                     and sexo=1
  58.                     and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
  59.                     and f4.tipo_esquema_indicado = 2
  60.                     and  concat(f4.nro_identificacion,f4.tipo_identificacion) not in
  61.                         (select distinct concat(f4.nro_identificacion,f4.tipo_identificacion)
  62.                         from formulario_f1 as f1 inner join formulario_f4_f7 as f4
  63.                         on concat(f1.nro_identificacion,f1.tipo_identificacion) = concat(f4.nro_identificacion,f4.tipo_identificacion)
  64.                         where f4.fecha_atencion between '2000-01-01' and '2014-08-19'
  65.                         and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  66.                         and sexo=1
  67.                         and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
  68.                         and f4.tipo_esquema_indicado=3
  69.                         )
  70.                     )
  71.                 group by concat(f5.nro_identificacion,f5.tipo_identificacion)
  72.                 having count(concat(f5.nro_identificacion,f5.tipo_identificacion))=1
  73.                 ) as t1) as ll, (select count(er) as er
  74.         from
  75.             (select distinct concat(nro_identificacion,tipo_identificacion) as er
  76.             from formulario_f5 as f5
  77.             where en_tarv = 1
  78.             and fecha_atencion between '2000-01-01' and '2014-08-19'
  79.             and concat(f5.nro_identificacion,f5.tipo_identificacion) in
  80.                 (select distinct concat(f4.nro_identificacion,f4.tipo_identificacion)
  81.                 from formulario_f1 as f1 inner join formulario_f4_f7 as f4
  82.                 on concat(f1.nro_identificacion,f1.tipo_identificacion) = concat(f4.nro_identificacion,f4.tipo_identificacion)
  83.                 where f4.fecha_atencion between '2000-01-01' and '2014-08-19'
  84.                 and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  85.                 and sexo=1
  86.                 and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
  87.                 and f4.tipo_esquema_indicado = 3
  88.                 )
  89.             group by concat(f5.nro_identificacion,f5.tipo_identificacion)
  90.             having count(concat(f5.nro_identificacion,f5.tipo_identificacion))=1
  91.             ) as t1) as er, -1 as total_status,-1 as total_acumulado
  92.         from (select concat(nro_identificacion,tipo_identificacion) as contax
  93.              from formulario_f1
  94.              where concat(nro_identificacion,tipo_identificacion) in
  95.                 (select concat(nro_identificacion,tipo_identificacion)
  96.                 from formulario_f1
  97.                 where fecha_atencion < '2000-01-01'
  98.                 and (DATEDIFF(now(),fecha_nacimiento)/360) <1
  99.                 and sexo=1
  100.                 and instalacion_salud_monitarv_asignada in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17))
  101.                 group by concat(nro_identificacion,tipo_identificacion)
  102.                 having count(concat(nro_identificacion,tipo_identificacion))=1
  103.             ) as canttot;