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 / testOrderByExtraValue.sql @ 46505
History | View | Annotate | Download (5.76 KB)
1 | 46104 | omartinez | |
---|---|---|---|
2 | -- ResultSetForSetProvider SQL
|
||
3 | |||
4 | -- Select
|
||
5 | 46105 | omartinez | SELECT
|
6 | 46505 | fdiaz | NULL AS "LID_CONDUCTOR", NULL AS "ID_ACCIDENTE", NULL AS "LID_VEHICULO", NULL AS "ID_VEHICULO", NULL AS "POSIBLE_RESPONSABLE", NULL AS "FECHA_NACIMIENTO", |
7 | NULL AS "SEXO", NULL AS "NACIONALIDAD", NULL AS "PAIS_RESIDENCIA", NULL AS "PROVINCIA_RESIDENCIA", NULL AS "MUNICIPIO_RESIDENCIA", NULL AS "ASISTENCIA_SANITARIA", |
||
8 | NULL AS "INFLU_FACT_ATENCION", NULL AS "FACTORES_ATENCION", NULL AS "INFLU_PRES_ERROR", NULL AS "PRESUNTOS_ERRORES", NULL AS "CARACT_PERMISO", |
||
9 | NULL AS "CLASE_PERMISO", NULL AS "FECHA_PERMISO", NULL AS "MOTIVO_DESPLAZAMIENTO", NULL AS "DESPLAZAMIENTO_PREVISTO", NULL AS "ACC_SEG_CINTURON", |
||
10 | 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", |
||
11 | NULL AS "ACC_SEG_PIES", NULL AS "ACC_SEG_PRENDA_REF", NULL AS "INFLU_ALCOHOL", NULL AS "PRUEBA_ALCOHOLEMIA", NULL AS "TASA_ALCOHOLEMIA1", |
||
12 | 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", |
||
13 | 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", |
||
14 | NULL AS "METH", NULL AS "CONFIRMADO_METH", NULL AS "OPI", NULL AS "CONFIRMADO_OPI", NULL AS "OTRAS", NULL AS "CONFIRMADO_OTRAS", |
||
15 | NULL AS "SIGNOS_INFLU_DROGAS", NULL AS "INFLU_PRES_INFRAC_COND", NULL AS "PRES_INFRAC_COND", NULL AS "PRES_INFRAC_SIN_LUCES", |
||
16 | NULL AS "PRES_INFRAC_SIN_TRIANGULO", NULL AS "INFLU_PRES_INFRAC_VEL", NULL AS "PRES_INFRAC_VEL_COND", NULL AS "INFLU_OTRA_INFRAC", |
||
17 | NULL AS "OTRA_INFRAC_COND", NULL AS "EXTRA", |
||
18 | EXTRACT(YEAR FROM "public"."ARENA2_ACCIDENTES"."FECHA_ACCIDENTE") AS "ano", |
||
19 | "public"."ARENA2_ACCIDENTES"."COD_PROVINCIA" AS "provincia", |
||
20 | 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", |
||
21 | SUM(1) AS "Acc" |
||
22 | 46105 | omartinez | FROM "public"."ARENA2_CONDUCTORES" |
23 | 46505 | fdiaz | LEFT JOIN "public"."ARENA2_ACCIDENTES" ON ( ("public"."ARENA2_CONDUCTORES"."ID_ACCIDENTE") = ("public"."ARENA2_ACCIDENTES"."ID_ACCIDENTE") ) |
24 | LEFT JOIN "public"."ARENA2_VEHICULOS" ON ( ("public"."ARENA2_CONDUCTORES"."LID_VEHICULO") = ("public"."ARENA2_VEHICULOS"."LID_VEHICULO") ) |
||
25 | 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'))) |
||
26 | 46105 | omartinez | GROUP BY |
27 | 46505 | fdiaz | 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 |
||
31 | "ano" ASC NULLS LAST, |
||
32 | "provincia" ASC NULLS LAST, |
||
33 | "lesividad" ASC NULLS LAST |
||
34 | 46105 | omartinez | LIMIT 15;
|
35 | 46104 | omartinez | |
36 | -- Count
|
||
37 | 46505 | fdiaz | SELECT COUNT(*) FROM ( SELECT 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", SUM(1) AS "Acc" 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 (("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 _subquery_alias_ ; |