Consultar los municipios que tengan en su población más de 2 mujeres
Publicado por andyman (2 intervenciones) el 27/04/2015 23:17:26
Amigos necesito ayuda para sacar esta consulta tengo las siguientes tablas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
CREATE TABLE genero (
gen_cod bigint NOT NULL,
gen_desc varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
INSERT INTO genero (gen_cod, gen_desc) VALUES
(1, 'Masculino'),
(2, 'Femenino'),
(3, 'otro');
CREATE TABLE municipio (
mun_cod bigint NOT NULL,
mun_nombre varchar(200) DEFAULT NULL,
nro_habitantes bigint DEFAULT NULL,
mun_pais_id bigint NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
INSERT INTO municipio (mun_cod, mun_nombre, nro_habitantes, mun_pais_id) VALUES
(1, 'Cundinamarca', 3000000, 1),
(4, 'Atlantico', 600000, 1),
(5, 'Antioquia', 800000, 1),
(6, 'San Isidro', 650000, 2),
(7, 'Cusco', 700000, 2),
(8, 'Gualaceo', 400000, 3),
(9, 'Guamote', 700000, 3);
CREATE TABLE IF NOT EXISTS `persona` (
`per_cod` bigint(20) NOT NULL,
`per_cedula` varchar(200) NOT NULL,
`per_nombre1` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
`per_nombre2` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
`per_apellido1` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
`per_apellido2` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
`per_doc_id` bigint(20) NOT NULL,
`per_tipo_id` bigint(20) NOT NULL,
`per_gen_id` bigint(20) NOT NULL,
`per_mun_id` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;
INSERT INTO `persona` (`per_cod`, `per_cedula`, `per_nombre1`, `per_nombre2`, `per_apellido1`, `per_apellido2`, `per_doc_id`, `per_tipo_id`, `per_gen_id`, `per_mun_id`) VALUES
(1, '101010', 'Camilo', 'Javier', 'Gonzales ', 'Diaz', 1, 1, 1, 1),
(2, 'e10112', 'Adriana', 'Lucia', 'Pereira ', 'Daza', 5, 1, 2, 4),
(3, '881001557854648', 'Santiago', 'Nilson', 'Neira ', 'Fernandez', 2, 1, 1, 5),
(4, '809162559-4', 'Saria', ' S.A.S.', ' ', ' ', 6, 2, 3, 5),
(5, '54483354', 'Ximena', 'Camila', 'Fray ', 'Donato', 5, 1, 2, 5),
(6, '448944563', 'Tarcicio', 'Inag', 'Foreh', 'Izuma', 1, 1, 1, 9),
(7, '88445336-4', 'Inadisa', 'S.A.S.', 'Entidad', 'privada', 6, 2, 3, 8),
(8, '144533987', 'Juliana', 'Andrea', 'Montalvo', 'Prada', 5, 1, 2, 7),
(9, '88455678-5', 'Bavaria', 'Sab ', 'Miller', 'Colombia', 6, 2, 3, 1),
(10, '904457866-4', 'Auteco', 'comercializadora', 'de motos', 'Cartagena', 6, 2, 3, 4),
(11, '45887866-4', 'Baloto', 'Rifas juegos y espectaculos', 'financiera', 'NIP', 6, 2, 3, 1),
(12, '10155521-4', 'Goodyear', 'Sede Bogota', 'Colombia', '1', 6, 2, 3, 1),
(13, '35454845', 'Maria', 'Camila', 'Blanco', 'Frix', 3, 1, 2, 5);
y tengo esta consulta
1
2
3
4
5
6
7
8
9
10
11
select muni.mun_nombre Municipio,count(1) 'cantidad de mujeres'
from
municipio muni,persona pers,genero gen
where
pers.per_gen_id=gen_cod
and
gen.gen_desc like '%femenino%'
and
pers.per_mun_id=muni.mun_cod
group by
muni.mun_nombre
la cual me dice cuantas mujeres hay en cada uno de los municipios sin embargo necesito que me muestre solamente cuando hay mas de 2 pero no he podido darle esa condicional
Valora esta pregunta
0