(SELECT CONCAT_WS(",",
MIN(gl.latitud) + (
(max(gl.latitud)-MIN(gl.latitud))/2),
MIN(gl.longitud) + (
(max(gl.longitud)-MIN(gl.longitud))/2) ) as puntitomedio
FROM geo_localizaciones gl,
loc_localizaciones ll, localidades l, municipios m,
provincias p, regiones r
WHERE
gl.id = ll.fk_geolocalizacion AND
ll.fk_localidad = l.id and
l.fk_municipio = m.id AND m.fk_provincia = p.id
AND p.fk_region = r.id AND r.nombre !="ceuta" AND
r.nombre <> "melilla" AND r.nombre NOT LIKE "%islas%");
SET @ESPANA=(SELECT COUNT(id) FROM localidades);
SET @ISLAS=(select COUNT(DISTINCT l.id)
from localidades l, municipios m,
provincias p, regiones r
where
l.fk_municipio = m.id and
m.fk_provincia = p.id and
p.fk_region = r.id and
(r.nombre like "%islas%" or
r.nombre = "ceuta" or r.nombre = "melilla"));
set @peninsula:=(select @espana-@islas);
set @lm:=39.840406;
set @lnm:=-2.9949505;
select concat(truncate(
count(distinct ll.fk_localidad)*100/@peninsula,2)," %") tp
from loc_localizaciones ll,
geo_localizaciones g where
ll.fk_geolocalizacion = g.id and
g.latitud<@lm and g.longitud>@lnm and
ll.fk_localidad NOT IN
(select l.id from localidades l, municipios m,
provincias p, regiones r
where
l.fk_municipio = m.id and m.fk_provincia = p.id and
p.fk_region = r.id and (r.nombre like "%islas%" or
r.nombre = "ceuta" or r.nombre = "melilla"));
¶ Cuenta cuantas localidades empiezan o terminan por «A» en Andalucía y Cataluña
select r.nombre, count(l.id)
from localidades l, municipios m,
provincias p, regiones r
where
(l.nombre like "a%" or l.nombre like "%a")
and
r.nombre in ("andalucia","cataluña")
and l.fk_municipio = m.id and
m.fk_provincia = p.id and
p.fk_region = r.id
group by r.nombre