By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select version();
create database if not exists demo;
use demo;
create table Todo_tbl (
id INT auto_increment,
person VARCHAR(45) ,
task VARCHAR(45) ,
duration INT(4),
deadline_day VARCHAR(2),
deadline_month VARCHAR(2),
PRIMARY KEY(id)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
insert into Todo_tbl values(1,'John', 'dust the floors', 40,04,03);
insert into Todo_tbl values(2,'Matt', 'do the dishes', 15,02,02);
insert into Todo_tbl values(3,'Mary', 'dusting', 40,03,02);
insert into Todo_tbl values(4,'Chloe', 'cleaning the windows', 65,04,05);
insert into Todo_tbl values(5,'John', 'wash the floors', 60,03,03);
insert into Todo_tbl values(6,'Bridget', 'take out the trash', 15,03,03);
insert into Todo_tbl values(7,'Matt', 'do the laundry', 18,02,02);
insert into Todo_tbl values(8,'Bridget', 'water the plants', 15,03,03);
select * from Todo_tbl;
create table Statistics_tbl with (
SELECT Todo_tbl.person, SUM(Todo_tbl.duration) FROM Todo_tbl JOIN Statistics_tbl
on Todo_tbl.person = Statistics_tbl.person GROUP BY person;
);
select * from Statistics_tbl;
version() |
---|
8.0.30 |
id | person | task | duration | deadline_day | deadline_month |
---|---|---|---|---|---|
1 | John | dust the floors | 40 | 4 | 3 |
2 | Matt | do the dishes | 15 | 2 | 2 |
3 | Mary | dusting | 40 | 3 | 2 |
4 | Chloe | cleaning the windows | 65 | 4 | 5 |
5 | John | wash the floors | 60 | 3 | 3 |
6 | Bridget | take out the trash | 15 | 3 | 3 |
7 | Matt | do the laundry | 18 | 2 | 2 |
8 | Bridget | water the plants | 15 | 3 | 3 |
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( SELECT Todo_tbl.person, SUM(Todo_tbl.duration) FROM Todo_tbl JOIN Statistics_t' at line 1