Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Grouping, counting and then grouping again
I need to create an SQL query where I want to count the number of children on a table. However, I want to group the select before I do the count in order to avoid repetition of another field. How can I do this?
Example:
Main table: events
child table: order definition
grand child table: parts
An event may have many orders, and an order may have many parts.
I want to select the events, and a count of the orders. However for an order to be valid it must have at least one part. So, I created an INNER JOIN between order and parts and an INNER JOIN between events and orders, and I want a count of orders. However, I need to get only one count for each order, even if it has many parts.
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement