When asking about databases it is important to show the design to get more adequate answers. Otherwise, we will have to imagine a suitable data model.
I imagine your model more or less like this:
- A table
inscripciones
that manages the people registered, in which workshop, and the attendances
- A table
personas
that stores the data of people
- A table
talleres
that does not appear here, but that would keep the peculiarities of each workshop
In the example I show a counter of assistants and of non assistants by workshop. I also show a list of the people who attended and those who did not, to know who are the negligent:)
You can also get the total number of registrants, saying who attended or not, etc. As you can see it is a flexible model. Imagine the same workshop that takes place in different days or sessions and you have to have attendance control per session, it would be very easy to adapt this model, either adding one or two columns to the table inscripciones
... or moving the column taller_id
to the table sesiones
and placing in turn a column sesion_id
in the table inscripciones
... When you create a data design you must also think about the future evolution of it.
I hope it serves you.
CREATE TABLE inscripciones (
taller_id INT,
persona_id INT,
asistio BOOLEAN
);
INSERT INTO inscripciones (taller_id, persona_id, asistio)
VALUES
(65,1,TRUE),
(65,2,TRUE),
(65,3,FALSE),
(65,4,TRUE),
(65,5,FALSE),
(65,6,TRUE),
(65,7,TRUE)
;
CREATE TABLE personas (
persona_id SERIAL,
persona_nom VARCHAR(50)
);
INSERT INTO personas (persona_nom)
VALUES
('Pedro'),
('Santiago'),
('Juan'),
('María'),
('Andrés'),
('Magdalena'),
('Sara')
;
-- Asistentes por taller
SELECT taller_id, COUNT(asistio) asistentes
FROM inscripciones WHERE asistio=TRUE GROUP BY taller_id;
-- No Asistentes por taller
SELECT taller_id, COUNT(asistio) asistentes
FROM inscripciones WHERE asistio=FALSE GROUP BY taller_id;
-- Asistentes al taller 65
SELECT p.persona_nom FROM personas p
INNER JOIN inscripciones i ON p.persona_id=i.persona_id
WHERE taller_id=65 AND asistio=TRUE;
-- No Asistentes al taller 65
SELECT p.persona_nom FROM personas p
INNER JOIN inscripciones i ON p.persona_id=i.persona_id
WHERE taller_id=65 AND asistio=FALSE;
Resultado:
--Total Asistentes
taller_id asistentes
1 65 5
--Total No Asistentes
taller_id no-asistentes
1 65 2
--Lista Asistentes
persona_nom
1 Pedro
2 Santiago
3 María
4 Magdalena
5 Sara
--Lista Negligentes :)
persona_nom
1 Juan
2 Andrés