Skip to content

Instantly share code, notes, and snippets.

@dagi3d
Created November 18, 2011 09:57
Show Gist options
  • Save dagi3d/1376048 to your computer and use it in GitHub Desktop.
Save dagi3d/1376048 to your computer and use it in GitHub Desktop.
$select = "b.pais AS pais , b.nombre_agente_ejecutor AS ong , c.descripcion_es AS Des_tipo, d.des_agrupacion_es AS agrupacion, d.descripcion_es AS Des_tema, e.des_mes_es, e.id_mes,f.desc_actividades_ag_es,SUM(a.num_activades) AS num_actividades, SUM(a.num_participantes) AS num_participantes";
$from = "agr_pi_actividades_mult_temas a, dim_organizacion_global b, dim_tipo_actividad_pi c, dim_tema_actividad d, dim_tiempo e, dim_actividades_agrupadas f";
$group_by = "b.pais, b.nombre_agente_ejecutor, c.descripcion_es, d.des_agrupacion_es, d.descripcion_es, e.des_mes_es,e.id_mes,f.desc_actividades_ag_es";
SELECT {$select}
FROM {$from}
WHERE
b.id_pais= ${pais}
AND -1 <> ${ong}
AND b.id_agente_ejecutor= ${ong}
AND b.sk_organizacion_global = a.sk_organizacion_global
AND a.sk_tipo_actividad = c.sk_tipo_actividad
AND a.sk_tema_actividad = d.sk_tema_actividad
AND -3 <> ${mes}
AND e.id_mes = ${mes}
AND e.id_anio= ${anio}
AND e.sk_fecha = a.sk_fecha
AND a.sk_actividades_ag=f.id_actividades_ag
GROUP BY {$group_by}
UNION ALL
SELECT {$select}
FROM {$from}
WHERE
b.id_pais= ${pais}
AND -1 <> ${ong}
AND b.id_agente_ejecutor= ${ong}
AND b.sk_organizacion_global = a.sk_organizacion_global
AND a.sk_tipo_actividad = c.sk_tipo_actividad
AND a.sk_tema_actividad = d.sk_tema_actividad
AND -3 = ${mes}
AND e.id_trimestre= ${tri}
AND e.id_anio= ${anio}
AND e.sk_fecha = a.sk_fecha
AND a.sk_actividades_ag=f.id_actividades_ag
GROUP BY {$group_by}
UNION ALL
SELECT {$select}
FROM {$from}
WHERE
b.id_pais= ${pais}
AND -1 = ${ong}
AND b.sk_organizacion_global = a.sk_organizacion_global
AND a.sk_tipo_actividad = c.sk_tipo_actividad
AND a.sk_tema_actividad = d.sk_tema_actividad
AND -3 = ${mes}
AND e.id_trimestre= ${tri}
AND e.id_anio= ${anio}
AND e.sk_fecha = a.sk_fecha
AND a.sk_actividades_ag=f.id_actividades_ag
GROUP BY {$group_by}
UNION ALL
SELECT {$select}
FROM {$from}
WHERE
b.id_pais= ${pais}
AND -1 = ${ong}
AND b.sk_organizacion_global = a.sk_organizacion_global
AND a.sk_tipo_actividad = c.sk_tipo_actividad
AND a.sk_tema_actividad = d.sk_tema_actividad
AND -3 <> ${mes}
AND e.id_mes= ${mes}
AND e.id_anio= ${anio}
AND e.sk_fecha = a.sk_fecha
AND a.sk_actividades_ag=f.id_actividades_ag
GROUP BY {$group_by}
ORDER BY pais, ong, des_mes_es,id_mes,Des_tipo, agrupacion,Des_tema,desc_actividades_ag_es;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment