I have a table like below
id |date |browser
---+———————————————————————+——————————————————————-
101|2024-03-12 00:00:00.000|Chrome |
102|2024-03-12 00:00:00.000|Firefox|
103|2024-03-13 00:00:00.000|Chrome |
104|2024-03-13 00:00:00.000|Firefox|
105|2024-03-13 00:00:00.000|Brave |
106|2024-03-14 00:00:00.000|Chrome |
107|2024-03-14 00:00:00.000|Firefox|
108|2024-03-14 00:00:00.000|Edge |
I want to count the occurances and insert the number of occurances in another database like below (into jsonb column). The browser is just as example of a string and can have many different type of values (i.e. it is not an enum type, so the values are unknown.)
id |date |json_count
---+———————————————————————+———————————————————————————————————————-
101|2024-03-12 00:00:00.000|{“Chrome”: 1, “Firefox”: 1} |
102|2024-03-13 00:00:00.000|{“Chrome”: 1, “Firefox”: 1, “Brave”: 1}|
103|2024-03-14 00:00:00.000|{“Chrome”: 1, “Firefox”: 1, “Edge”: 1} |
How do i achieve this in a sql query?