svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial / org.gvsig.h2spatial.h2gis132 / org.gvsig.h2spatial.h2gis132.provider / src / test / resources / org / gvsig / fmap / dal / store / h2 / usecases / arena2 / testGroupByForeignValue.sql @ 46517
History | View | Annotate | Download (5.55 KB)
1 |
|
---|---|
2 |
-- Select
|
3 |
SELECT
|
4 |
NULL AS "LID_CONDUCTOR", NULL AS "ID_ACCIDENTE", NULL AS "LID_VEHICULO", NULL AS "ID_VEHICULO", NULL AS "POSIBLE_RESPONSABLE", |
5 |
NULL AS "FECHA_NACIMIENTO", NULL AS "SEXO", NULL AS "NACIONALIDAD", NULL AS "PAIS_RESIDENCIA", NULL AS "PROVINCIA_RESIDENCIA", |
6 |
NULL AS "MUNICIPIO_RESIDENCIA", NULL AS "ASISTENCIA_SANITARIA", NULL AS "INFLU_FACT_ATENCION", NULL AS "FACTORES_ATENCION", |
7 |
NULL AS "INFLU_PRES_ERROR", NULL AS "PRESUNTOS_ERRORES", NULL AS "CARACT_PERMISO", NULL AS "CLASE_PERMISO", NULL AS "FECHA_PERMISO", |
8 |
NULL AS "MOTIVO_DESPLAZAMIENTO", NULL AS "DESPLAZAMIENTO_PREVISTO", NULL AS "ACC_SEG_CINTURON", NULL AS "ACC_SEG_CASCO", |
9 |
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", |
10 |
NULL AS "ACC_SEG_PIES", NULL AS "ACC_SEG_PRENDA_REF", NULL AS "INFLU_ALCOHOL", NULL AS "PRUEBA_ALCOHOLEMIA", NULL AS "TASA_ALCOHOLEMIA1", |
11 |
NULL AS "TASA_ALCOHOLEMIA2", NULL AS "PRUEBA_ALC_SANGRE", NULL AS "SIGNOS_INFLU_ALCOHOL", NULL AS "INFLU_DROGAS", NULL AS "PRUEBA_DROGAS", |
12 |
NULL AS "AMP", NULL AS "CONFIRMADO_AMP", NULL AS "BDZ", NULL AS "CONFIRMADO_BDZ", NULL AS "COC", NULL AS "CONFIRMADO_COC", NULL AS "THC", |
13 |
NULL AS "CONFIRMADO_THC", NULL AS "METH", NULL AS "CONFIRMADO_METH", NULL AS "OPI", NULL AS "CONFIRMADO_OPI", NULL AS "OTRAS", |
14 |
NULL AS "CONFIRMADO_OTRAS", NULL AS "SIGNOS_INFLU_DROGAS", NULL AS "INFLU_PRES_INFRAC_COND", NULL AS "PRES_INFRAC_COND", |
15 |
NULL AS "PRES_INFRAC_SIN_LUCES", NULL AS "PRES_INFRAC_SIN_TRIANGULO", NULL AS "INFLU_PRES_INFRAC_VEL", NULL AS "PRES_INFRAC_VEL_COND", |
16 |
NULL AS "INFLU_OTRA_INFRAC", NULL AS "OTRA_INFRAC_COND", NULL AS "EXTRA", |
17 |
EXTRACT(YEAR FROM "PUBLIC"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE") AS "ano", |
18 |
"PUBLIC"."ARENA2_ACCIDENTES"."COD_PROVINCIA" AS "provincia", |
19 |
CASE WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 3) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 4)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 5)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 6)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END AS "lesividad", |
20 |
SUM(1) AS "Acc" |
21 |
FROM "PUBLIC"."ARENA2_CONDUCTORES" |
22 |
LEFT JOIN "PUBLIC"."ARENA2_ACCIDENTES" ON ( ("PUBLIC"."ARENA2_CONDUCTORES"."ID_ACCIDENTE") = ("PUBLIC"."ARENA2_ACCIDENTES"."ID_ACCIDENTE") ) |
23 |
LEFT JOIN "PUBLIC"."ARENA2_VEHICULOS" ON ( ("PUBLIC"."ARENA2_CONDUCTORES"."LID_VEHICULO") = ("PUBLIC"."ARENA2_VEHICULOS"."LID_VEHICULO") ) |
24 |
WHERE
|
25 |
((("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'))) |
26 |
GROUP BY |
27 |
EXTRACT(YEAR FROM "PUBLIC"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE"), |
28 |
"PUBLIC"."ARENA2_ACCIDENTES"."COD_PROVINCIA", |
29 |
CASE WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 3) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 4)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 5)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 6)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END |
30 |
ORDER BY "PUBLIC"."ARENA2_ACCIDENTES"."COD_PROVINCIA" ASC NULLS LAST; |
31 |
|
32 |
|
33 |
-- Count
|
34 |
SELECT COUNT(*) FROM ( |
35 |
SELECT SUM(1) AS "Acc" |
36 |
FROM "PUBLIC"."ARENA2_CONDUCTORES" |
37 |
LEFT JOIN "PUBLIC"."ARENA2_ACCIDENTES" |
38 |
ON ( ("PUBLIC"."ARENA2_CONDUCTORES"."ID_ACCIDENTE") = ("PUBLIC"."ARENA2_ACCIDENTES"."ID_ACCIDENTE") ) |
39 |
LEFT JOIN "PUBLIC"."ARENA2_VEHICULOS" |
40 |
ON ( ("PUBLIC"."ARENA2_CONDUCTORES"."LID_VEHICULO") = ("PUBLIC"."ARENA2_VEHICULOS"."LID_VEHICULO") ) |
41 |
WHERE ((("PUBLIC"."ARENA2_ACCIDENTES"."TITULARIDAD_VIA" = 2) AND |
42 |
((("PUBLIC"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 5) |
43 |
OR ("PUBLIC"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 6)) |
44 |
OR ("PUBLIC"."ARENA2_VEHICULOS"."TIPO_VEHICULO" = 7))) |
45 |
AND (("PUBLIC"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" >= DATE '2019-01-01') |
46 |
AND ("PUBLIC"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE" <= DATE '2019-12-31'))) |
47 |
GROUP BY |
48 |
EXTRACT(YEAR FROM "PUBLIC"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE"), |
49 |
"PUBLIC"."ARENA2_ACCIDENTES"."COD_PROVINCIA", |
50 |
CASE WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 1)) THEN ('Muerto') WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 2)) THEN ('Grave') WHEN (((((("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 3) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 4)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 5)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 6)) OR ("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 7))) THEN ('Leve') WHEN (("PUBLIC"."ARENA2_CONDUCTORES"."ASISTENCIA_SANITARIA" = 8)) THEN ('Ileso') ELSE ('Se Desconoce') END |
51 |
) AS _subquery_alias_;
|