By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table groups ( id int, grpid int , changeDate date, userid int, pct double , hobby int );
SELECT * from groups;
insert into groups(id , grpid , changeDate ,userid ,pct ,hobby ) values
(1 , 1 ,'2020-01-01', 1 , 1 , 1 ),
(2 , 1 ,'2020-01-02', 1 , 1 , 2 ),
(3 , 1 ,'2020-01-03', 1 , 1 , 1 ),
(4 , 2 ,'2020-01-01', 1 , 0.5 , 1 ),
(5 , 2 ,'2020-01-01', 2 , 0.5 , 2 ),
(6 , 2 ,'2020-01-02', 1 , 0.5 , 1 ),
(7 , 2 ,'2020-01-02', 2 , 0.5 , 3 ),
(8 , 3 ,'2020-01-01', 1 , 0.5 , 1 ),
(9 , 3 ,'2020-01-01', 2 , 0.5 , 2 ),
(10 , 3 ,'2020-01-02', 1 , 0.4 , 1 ),
(11 , 3 ,'2020-01-02', 2 , 0.6 , 2 ),
(12 , 4 ,'2020-01-01', 1 , 0.6 , 1 ),
(13 , 4 ,'2020-01-01', 2 , 0.4 , 2 ),
(14 , 4 ,'2020-01-02', 1 , 0.6 , 1 ),
(15 , 4 ,'2020-01-02', 2 , 0.4 , 2 ),
(16 , 5 ,'2020-01-01', 1 , 0.2 , 2 ),
(17 , 5 ,'2020-01-01', 2 , 0.5 , 1 ),
(18 , 5 ,'2020-01-01', 3 , 0.3 , 2 ),
(19 , 6 ,'2020-01-01', 1 , 0.3 , 2 ),
(20 , 6 ,'2020-01-01', 2 , 0.5 , 1 ),
(21 , 6 ,'2020-01-01', 3 , 0.2 , 2 ),
(22 , 6 ,'2020-02-01', 1 , 0.2 , 2 ),
(23 , 6 ,'2020-02-01', 2 , 0.5 , 1 ),
(24 , 6 ,'2020-02-01', 3 , 0.3 , 2 ),
(25 , 6 ,'2020-03-01', 1 , 0.3 , 2 ),
(26 , 6 ,'2020-03-01', 2 , 0.3 , 1 ),
(27 , 6 ,'2020-03-01', 3 , 0.4 , 2 ),
(28 , 7 ,'2020-01-01', 1 , 0.3 , 2 ),
(29 , 7 ,'2020-01-01', 2 , 0.5 , 1 ),
(30 , 7 ,'2020-01-01', 3 , 0.2 , 2 ),
(31 , 7 ,'2020-02-01', 1 , 0.3 , 2 ),
(32 , 7 ,'2020-02-01', 2 , 0.5 , 1 ),
(33 , 7 ,'2020-02-01', 3 , 0.2 , 2 ),
(34 , 7 ,'2020-03-01', 1 , 0.3 , 2 ),
(35 , 7 ,'2020-03-01', 2 , 0.3 , 1 ),
SELECT * from groups;
id | grpid | changeDate | userid | pct | hobby |
---|---|---|---|---|---|
1 | 1 | 2020-01-01 | 1 | 1 | 1 |
2 | 1 | 2020-01-02 | 1 | 1 | 2 |
3 | 1 | 2020-01-03 | 1 | 1 | 1 |
4 | 2 | 2020-01-01 | 1 | 0.5 | 1 |
5 | 2 | 2020-01-01 | 2 | 0.5 | 2 |
6 | 2 | 2020-01-02 | 1 | 0.5 | 1 |
7 | 2 | 2020-01-02 | 2 | 0.5 | 3 |
8 | 3 | 2020-01-01 | 1 | 0.5 | 1 |
9 | 3 | 2020-01-01 | 2 | 0.5 | 2 |
10 | 3 | 2020-01-02 | 1 | 0.4 | 1 |
11 | 3 | 2020-01-02 | 2 | 0.6 | 2 |
12 | 4 | 2020-01-01 | 1 | 0.6 | 1 |
13 | 4 | 2020-01-01 | 2 | 0.4 | 2 |
14 | 4 | 2020-01-02 | 1 | 0.6 | 1 |
15 | 4 | 2020-01-02 | 2 | 0.4 | 2 |
16 | 5 | 2020-01-01 | 1 | 0.2 | 2 |
17 | 5 | 2020-01-01 | 2 | 0.5 | 1 |
18 | 5 | 2020-01-01 | 3 | 0.3 | 2 |
19 | 6 | 2020-01-01 | 1 | 0.3 | 2 |
20 | 6 | 2020-01-01 | 2 | 0.5 | 1 |
21 | 6 | 2020-01-01 | 3 | 0.2 | 2 |
22 | 6 | 2020-02-01 | 1 | 0.2 | 2 |
23 | 6 | 2020-02-01 | 2 | 0.5 | 1 |
24 | 6 | 2020-02-01 | 3 | 0.3 | 2 |
25 | 6 | 2020-03-01 | 1 | 0.3 | 2 |
26 | 6 | 2020-03-01 | 2 | 0.3 | 1 |
27 | 6 | 2020-03-01 | 3 | 0.4 | 2 |
28 | 7 | 2020-01-01 | 1 | 0.3 | 2 |
29 | 7 | 2020-01-01 | 2 | 0.5 | 1 |
30 | 7 | 2020-01-01 | 3 | 0.2 | 2 |
31 | 7 | 2020-02-01 | 1 | 0.3 | 2 |
32 | 7 | 2020-02-01 | 2 | 0.5 | 1 |
33 | 7 | 2020-02-01 | 3 | 0.2 | 2 |
34 | 7 | 2020-03-01 | 1 | 0.3 | 2 |
35 | 7 | 2020-03-01 | 2 | 0.3 | 1 |
36 | 7 | 2020-03-01 | 3 | 0.4 | 2 |