CREATE TABLE presenze (
Id INTEGER PRIMARY KEY,
nomecognome TEXT NOT NULL,
presenzadata date NOT NULL,
ore INTEGER not null
);
INSERT INTO presenze VALUES (0001, 'pippo', '2024-01-01', 8);
INSERT INTO presenze VALUES (0002, 'pluto', '2024-01-01', 8);
INSERT INTO presenze VALUES (0003, 'pippo', '2024-01-02', 8);
INSERT INTO presenze VALUES (0004, 'pluto', '2024-01-02', 3);
INSERT INTO presenze VALUES (0005, 'pippo', '2024-01-03', 1);
INSERT INTO presenze VALUES (0006, 'pluto', '2024-01-03', 8);
INSERT INTO presenze VALUES (0007, 'pluto', '2024-01-04', 3);
+----+-------------+--------------+-----+
| Id | nomecognome | presenzadata | ore |
+----+-------------+--------------+-----+
| 1 | pippo | 2024-01-01 | 8 |
| 2 | pluto | 2024-01-01 | 8 |
| 3 | pippo | 2024-01-02 | 8 |
| 4 | pluto | 2024-01-02 | 3 |
| 5 | pippo | 2024-01-03 | 1 |
| 6 | pluto | 2024-01-03 | 8 |
| 7 | pluto | 2024-01-04 | 3 |
+----+-------------+--------------+-----+
SELECT sum(ore) FROM presenze where nomecognome='pippo' and (presenzadata>'2023-12-31' and presenzadata<'2024-01-03');
select count(nomecognome) from presenze where nomecognome='pippo' and (presenzadata>'2023-12-31' and presenzadata<'2024-01-03');
risultati per pippo dal 01/01/2024 al 02/01/2024
+----------+
| sum(ore) |
+----------+
| 16 |
+----------+
+--------------------+
| count(nomecognome) |
+--------------------+
| 2 |
+--------------------+
easy... but you have a bug!