PostgreSQL JOIN with array type with array elements order, how to implement?

前端 未结 4 1151
梦谈多话
梦谈多话 2020-12-02 13:04

I have two tables in database:

CREATE TABLE items(
 id SERIAL PRIMARY KEY,
 ... some other fields
);

This table contains come data row with

4条回答
  •  时光说笑
    2020-12-02 13:49

    select distinct on (some_chosen_data_in_order.id)
      some_chosen_data_in_order.*,
       array_to_json( array_agg(row_to_json( items))
      over ( partition by some_chosen_data_in_order.id ))
    from some_chosen_data_in_order
      left join items on items.id = any (some_chosen_data_in_order.id_items)
    

提交回复
热议问题