[SQL] calcul pour chaque catégorie le nombre d'entités
Bonjour,
J'ai 3 tables dans ma base de données: "categorie", "activite", "entite", que je vous les joint.
Je veux savoir le nombre d'(entite) dans chaque (categorie).
Au début j'avais une idée de créer 3 requêtes SQL et faire des boucles (while) mais ça ne va pas. est ce qu'il y a une fonction prédéfinie en php me permet de faire ce calcule sans utiliser 3 requêtes?
Comment faire ça?
Code:
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
|
CREATE TABLE `categorie` (
`code_categorie` int(11) NOT NULL auto_increment,
`libelle_categorie` varchar(50) NOT NULL,
PRIMARY KEY (`code_categorie`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
CREATE TABLE `activite` (
`code_activite` int(11) NOT NULL auto_increment,
`libelle_activite` varchar(50) NOT NULL,
`code_categorie` int(11) NOT NULL,
`icone_activite` varchar(50) NOT NULL,
PRIMARY KEY (`code_activite`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=61 ;
CREATE TABLE `entite` (
`code_entite` int(11) NOT NULL auto_increment,
`nom_entite` varchar(50) NOT NULL,
`description_entite` varchar(2500) NOT NULL,
`adresse_entite` int(11) NOT NULL,
`bp` int(11) NOT NULL,
`code_postal` int(11) NOT NULL,
`url_entite` varchar(50) NOT NULL,
`tel_entite` int(11) NOT NULL,
`mail_entite` varchar(50) NOT NULL,
`fax_entite` int(11) NOT NULL,
`code_activite` int(11) NOT NULL,
`lat` decimal(10,6) NOT NULL,
`lng` decimal(10,6) NOT NULL,
`image` varchar(50) NOT NULL,
PRIMARY KEY (`code_entite`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ; |
Merci d'avance