I have a table so . The table stores the attendance record ( P ) and faults ( F ). I need to tell, for example, how many presences and how many faults a particular code has.
I have a table so . The table stores the attendance record ( P ) and faults ( F ). I need to tell, for example, how many presences and how many faults a particular code has.
I would do it as follows:
CREATE TABLE IF NOT EXISTS 'frequencia' (
'idFrequencia' int(10) NOT NULL AUTO_INCREMENT,
'idUsuario' int(10) NOT NULL,
'diaSemana' int(10) NOT NULL,
'presenca' int(10) NOT NULL,
PRIMARY KEY ('idFrequencia')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
INSERT INTO 'frequencia'
('idFrequencia', 'idUsuario', 'diaSemana', 'presenca')
VALUES
(1, 1, 1, 1),
(2, 1, 2, 1),
(3, 1, 3, 2),
(4, 1, 4, 2),
(5, 1, 5, 1);
And then I would do a SQL:
SELECT count(idFrequencia) as qtdFalta FROM frequencia WHERE idUSuario = '1' GROUP BY presenca = '2';
To get the results. It's an option!