Index: testGroupByForeignValue.sql
===================================================================
--- testGroupByForeignValue.sql	(revision 46104)
+++ testGroupByForeignValue.sql	(revision 46105)
@@ -2,7 +2,8 @@
 -- ResultSetForSetProvider SQL
 
 -- Select 
-SELECT NULL AS "LID_CONDUCTOR", NULL AS "ID_ACCIDENTE", NULL AS "LID_VEHICULO", NULL AS "ID_VEHICULO", NULL AS "POSIBLE_RESPONSABLE", NULL AS "FECHA_NACIMIENTO", NULL AS "SEXO", NULL AS "NACIONALIDAD", NULL AS "PAIS_RESIDENCIA", NULL AS "PROVINCIA_RESIDENCIA", NULL AS "MUNICIPIO_RESIDENCIA", NULL AS "ASISTENCIA_SANITARIA", NULL AS "INFLU_FACT_ATENCION", NULL AS "FACTORES_ATENCION", NULL AS "INFLU_PRES_ERROR", NULL AS "PRESUNTOS_ERRORES", NULL AS "CARACT_PERMISO", NULL AS "CLASE_PERMISO", NULL AS "FECHA_PERMISO", NULL AS "MOTIVO_DESPLAZAMIENTO", NULL AS "DESPLAZAMIENTO_PREVISTO", NULL AS "ACC_SEG_CINTURON", NULL AS "ACC_SEG_CASCO", NULL AS "ACC_SEG_BRAZOS", NULL AS "ACC_SEG_ESPALDA", NULL AS "ACC_SEG_TORSO", NULL AS "ACC_SEG_MANOS", NULL AS "ACC_SEG_PIERNAS", NULL AS "ACC_SEG_PIES", NULL AS "ACC_SEG_PRENDA_REF", NULL AS "INFLU_ALCOHOL", NULL AS "PRUEBA_ALCOHOLEMIA", NULL AS "TASA_ALCOHOLEMIA1", NULL AS "TASA_ALCOHOLEMIA2", NULL AS "PRUEBA_ALC_SANGRE", NULL AS "SIGNOS_INFLU_ALCOHOL", NULL AS "INFLU_DROGAS", NULL AS "PRUEBA_DROGAS", NULL AS "AMP", NULL AS "CONFIRMADO_AMP", NULL AS "BDZ", NULL AS "CONFIRMADO_BDZ", NULL AS "COC", NULL AS "CONFIRMADO_COC", NULL AS "THC", NULL AS "CONFIRMADO_THC", NULL AS "METH", NULL AS "CONFIRMADO_METH", NULL AS "OPI", NULL AS "CONFIRMADO_OPI", NULL AS "OTRAS", NULL AS "CONFIRMADO_OTRAS", NULL AS "SIGNOS_INFLU_DROGAS", NULL AS "INFLU_PRES_INFRAC_COND", NULL AS "PRES_INFRAC_COND", NULL AS "PRES_INFRAC_SIN_LUCES", NULL AS "PRES_INFRAC_SIN_TRIANGULO", NULL AS "INFLU_PRES_INFRAC_VEL", NULL AS "PRES_INFRAC_VEL_COND", NULL AS "INFLU_OTRA_INFRAC", NULL AS "OTRA_INFRAC_COND", NULL AS "EXTRA", SUM(1) AS "Acc", EXTRACT(YEAR FROM "public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE") AS "ano", "public"."ARENA2_ACCIDENTES"."COD_PROVINCIA" AS "provincia", CASE WHEN (("ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("ASISTENCIA_SANITARIA" = 3) OR ("ASISTENCIA_SANITARIA" = 4)) OR ("ASISTENCIA_SANITARIA" = 5)) OR ("ASISTENCIA_SANITARIA" = 6)) OR ("ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END AS "lesividad" FROM "public"."ARENA2_CONDUCTORES" LEFT JOIN "public"."ARENA2_ACCIDENTES" ON ( ("public"."ARENA2_CONDUCTORES"."ID_ACCIDENTE") = ("public"."ARENA2_ACCIDENTES"."ID_ACCIDENTE") ) LEFT JOIN "public"."ARENA2_VEHICULOS" ON ( ("public"."ARENA2_CONDUCTORES"."LID_VEHICULO") = ("public"."ARENA2_VEHICULOS"."LID_VEHICULO") ) WHERE ((("public"."ARENA2_ACCIDENTES"."TITULARIDAD_VIA" = 2) AND ((("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 5) OR ("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 6)) OR ("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 7))) AND (("public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" >= DATE '2019-01-01') AND ("public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" <= DATE '2019-12-31'))) GROUP BY EXTRACT(YEAR FROM "public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE"), "public"."ARENA2_ACCIDENTES"."COD_PROVINCIA", CASE WHEN (("ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("ASISTENCIA_SANITARIA" = 3) OR ("ASISTENCIA_SANITARIA" = 4)) OR ("ASISTENCIA_SANITARIA" = 5)) OR ("ASISTENCIA_SANITARIA" = 6)) OR ("ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END ORDER BY "provincia" ASC, "LID_CONDUCTOR" ASC;
+SELECT NULL AS "LID_CONDUCTOR", NULL AS "ID_ACCIDENTE", NULL AS "LID_VEHICULO", NULL AS "ID_VEHICULO", NULL AS "POSIBLE_RESPONSABLE", NULL AS "FECHA_NACIMIENTO", NULL AS "SEXO", NULL AS "NACIONALIDAD", NULL AS "PAIS_RESIDENCIA", NULL AS "PROVINCIA_RESIDENCIA", NULL AS "MUNICIPIO_RESIDENCIA", NULL AS "ASISTENCIA_SANITARIA", NULL AS "INFLU_FACT_ATENCION", NULL AS "FACTORES_ATENCION", NULL AS "INFLU_PRES_ERROR", NULL AS "PRESUNTOS_ERRORES", NULL AS "CARACT_PERMISO", NULL AS "CLASE_PERMISO", NULL AS "FECHA_PERMISO", NULL AS "MOTIVO_DESPLAZAMIENTO", NULL AS "DESPLAZAMIENTO_PREVISTO", NULL AS "ACC_SEG_CINTURON", NULL AS "ACC_SEG_CASCO", NULL AS "ACC_SEG_BRAZOS", NULL AS "ACC_SEG_ESPALDA", NULL AS "ACC_SEG_TORSO", NULL AS "ACC_SEG_MANOS", NULL AS "ACC_SEG_PIERNAS", NULL AS "ACC_SEG_PIES", NULL AS "ACC_SEG_PRENDA_REF", NULL AS "INFLU_ALCOHOL", NULL AS "PRUEBA_ALCOHOLEMIA", NULL AS "TASA_ALCOHOLEMIA1", NULL AS "TASA_ALCOHOLEMIA2", NULL AS "PRUEBA_ALC_SANGRE", NULL AS "SIGNOS_INFLU_ALCOHOL", NULL AS "INFLU_DROGAS", NULL AS "PRUEBA_DROGAS", NULL AS "AMP", NULL AS "CONFIRMADO_AMP", NULL AS "BDZ", NULL AS "CONFIRMADO_BDZ", NULL AS "COC", NULL AS "CONFIRMADO_COC", NULL AS "THC", NULL AS "CONFIRMADO_THC", NULL AS "METH", NULL AS "CONFIRMADO_METH", NULL AS "OPI", NULL AS "CONFIRMADO_OPI", NULL AS "OTRAS", NULL AS "CONFIRMADO_OTRAS", NULL AS "SIGNOS_INFLU_DROGAS", NULL AS "INFLU_PRES_INFRAC_COND", NULL AS "PRES_INFRAC_COND", NULL AS "PRES_INFRAC_SIN_LUCES", NULL AS "PRES_INFRAC_SIN_TRIANGULO", NULL AS "INFLU_PRES_INFRAC_VEL", NULL AS "PRES_INFRAC_VEL_COND", NULL AS "INFLU_OTRA_INFRAC", NULL AS "OTRA_INFRAC_COND", NULL AS "EXTRA", SUM(1) AS "Acc", EXTRACT(YEAR FROM "public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE") AS "ano", "public"."ARENA2_ACCIDENTES"."COD_PROVINCIA" AS "provincia", CASE WHEN (("ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("ASISTENCIA_SANITARIA" = 3) OR ("ASISTENCIA_SANITARIA" = 4)) OR ("ASISTENCIA_SANITARIA" = 5)) OR ("ASISTENCIA_SANITARIA" = 6)) OR ("ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END AS "lesividad" FROM "public"."ARENA2_CONDUCTORES" LEFT JOIN "public"."ARENA2_ACCIDENTES" ON ( ("public"."ARENA2_CONDUCTORES"."ID_ACCIDENTE") = ("public"."ARENA2_ACCIDENTES"."ID_ACCIDENTE") ) LEFT JOIN "public"."ARENA2_VEHICULOS" ON ( ("public"."ARENA2_CONDUCTORES"."LID_VEHICULO") = ("public"."ARENA2_VEHICULOS"."LID_VEHICULO") ) WHERE ((("public"."ARENA2_ACCIDENTES"."TITULARIDAD_VIA" = 2) AND ((("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 5) OR ("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 6)) OR ("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 7))) AND (("public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" >= DATE '2019-01-01') AND ("public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" <= DATE '2019-12-31'))) GROUP BY EXTRACT(YEAR FROM "public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE"), "public"."ARENA2_ACCIDENTES"."COD_PROVINCIA", CASE WHEN (("ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("ASISTENCIA_SANITARIA" = 3) OR ("ASISTENCIA_SANITARIA" = 4)) OR ("ASISTENCIA_SANITARIA" = 5)) OR ("ASISTENCIA_SANITARIA" = 6)) OR ("ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END 
+ORDER BY "provincia" ASC, "ano" ASC, "lesividad" ASC, "LID_CONDUCTOR" ASC;
 
 -- Count
 SELECT COUNT(*) FROM ( SELECT COUNT(*) FROM "public"."ARENA2_CONDUCTORES" LEFT JOIN "public"."ARENA2_ACCIDENTES" ON ( ("public"."ARENA2_CONDUCTORES"."ID_ACCIDENTE") = ("public"."ARENA2_ACCIDENTES"."ID_ACCIDENTE") ) LEFT JOIN "public"."ARENA2_VEHICULOS" ON ( ("public"."ARENA2_CONDUCTORES"."LID_VEHICULO") = ("public"."ARENA2_VEHICULOS"."LID_VEHICULO") ) WHERE ((("public"."ARENA2_ACCIDENTES"."TITULARIDAD_VIA" = 2) AND ((("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 5) OR ("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 6)) OR ("public"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 7))) AND (("public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" >= DATE '2019-01-01') AND ("public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" <= DATE '2019-12-31'))) GROUP BY EXTRACT(YEAR FROM "public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE"), "public"."ARENA2_ACCIDENTES"."COD_PROVINCIA", CASE WHEN (("ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("ASISTENCIA_SANITARIA" = 3) OR ("ASISTENCIA_SANITARIA" = 4)) OR ("ASISTENCIA_SANITARIA" = 5)) OR ("ASISTENCIA_SANITARIA" = 6)) OR ("ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END) as _subquery_alias_ ;
