Answer the question
In order to leave comments, you need to log in
How to merge 2 records into one by attribute?
I don't know if I phrased my question correctly, but I hope you understand from the pictures.
I know what I want, but how to formulate it correctly, based on SQL terms - xs, so a Google search did not give any results.
There is a table T (1 fig.). It has 2 entries referring to the same T.office_id. How to compose a query so that it turns out like in Figure 2? It is necessary that the output already has one record with new columns T.employee_id_first and T.employee_id_second and, accordingly, T.office_id
I will be glad for any help.
Answer the question
In order to leave comments, you need to log in
You can directly get an array from the base:
select
office_id,
json_arrayagg(employee_id) employee_ids
from t
group by office_id;
+===========+==============+
| office_id | employee_ids |
+===========+==============+
| 1 | [1, 2] |
+-----------+--------------+
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question