I have 2 tables where the values are as follows:
Table a:
| Date | Time | Count |
===============================================
| D1 | T1 | 0 |
| D1 | T2 | 0 |
| D2 | T1 | 0 |
| D2 | T2 | 0 |
Table B:
| Date | Time | Value |
===============================================
| D1 | T1 | a |
| D1 | T1 | b |
| D1 | T1 | c |
| D1 | T2 | e |
| D2 | T1 | f |
| D2 | T1 | g |
| D2 | T1 | h |
| D2 | T2 | i |
| D2 | T2 | j |
I am trying to create a query that could count the quantity Valuefrom Table Band insert the result into a column CountfromTable A
Where the result should show (in table A):
| Date | Time | Count |
===============================================
| D1 | T1 | 3 |
| D1 | T2 | 1 |
| D2 | T1 | 3 |
| D2 | T2 | 2 |
I tried using regular UPDATE with code:
UPDATE A
SET Count = (SELECT COUNT(Value)
FROM B, A
WHERE A.Date = B.Date
and A.Time = B.Time)
However, this led to the fact that all Count became 9 instead of showing each date and time, its value set
I could not create an identifier for each date and time, as the values of the Date and Time column will change every hour
Is there something wrong with my code, or is there any other way to get closer to this?
Thank you in advance for your help.