Вопрос

i'm working with sqlite right now,

i want to merging some column that have a same parent id but different child id each every group;

this is my table;

+---------+----------+
|id_boss  | id_child |       
+---------+----------+
|   2     |     1    | 
|   2     |     9    |  
|   5     |     3    | 
|   5     |     4    |
|   6     |     7    | 
|   6     |     8    |
+---------+----------+ 

and i'm looking a way to combine column id_child

and the result would be something like this :

+---------+-----------+-----------+
|id_boss  | id_child1 | id_child2 |     
+---------+-----------+-----------+
|   2     |     1     |     9     |
|   5     |     3     |     4     |
|   6     |     7     |     8     |
+---------+-----------+-----------+ 

id_child first row group id_boss is in id_child1 and second row group id_boss is in id_child2

Это было полезно?

Решение

select id_boss, 
       min(id_child) as id_child1,
       max(id_child) as id_child2
from your_table
group by id_boss
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top