I have two tables:
Table A:
ID | CODE | time-stamp |
---|---|---|
Aid_z | code_z | 2020-07-21 |
... | ... | ... |
Aid_1 | code_1 | 2020-11-30 |
Aid_2 | code_2 | 2020-11-30 |
Aid_3 | code_2 | 2020-11-30 |
Aid_4 | code_1 | 2020-11-30 |
Aid_5 | code_3 | 2020-11-30 |
... | ... | ... |
Aid_n | code_x | 2021-04-06 |
ID is unique, there is 67 distinct CODEs.
Table B:
ID | ID_A | status | value | time-stamp |
---|---|---|---|---|
Bid_z | Aid_z | z | ... | 2020-07-21 |
... | ... | ... | ... | ... |
Bid_1 | Aid_1 | 1 | 101.1 | 2020-11-30 |
Bid_2 | Aid_2 | 0 | 87.6 | 2020-11-30 |
Bid_3 | Aid_3 | 0 | 76.2 | 2020-11-30 |
Bid_4 | Aid_4 | 1 | 106.2 | 2020-11-30 |
Bid_5 | Aid_5 | 2 | 124.6 | 2020-11-30 |
... | ... | ... | ... | ... |
Bid_n | Aid_n | x | ... | 2021-04-06 |
ID is unique, ID_A is the same as ID from Table A.
What I need to do is:
- Count how much of all records are each day
- Count amount of each distinct CODEs
- Present them as a columns and each row should be representing one day
- Only for status "0" or "1" from Table B
- Only for records between 2020-11-30 and 2021-02-06
In the end reasult should looks like:
date (per day) | sum_of_this_day | code_1 | code_2 | code_2 | ... | code_z |
---|---|---|---|---|---|---|
2020-11-30 | 35 | 5 | 0 | 10 | ... | x |
2020-11-31 | 60 | 6 | 5 | 12 | ... | x |
... | ... | ... | ... | ... | ... | ... |
2021-02-06 | 47 | 6 | 5 | 12 | ... | x |