postgresql json aggregate

前端 未结 2 1206
生来不讨喜
生来不讨喜 2021-02-14 10:10

I\'m using postgres 9.4, I have the following query:

SELECT pid, code, name FROM activity, (
  SELECT code FROM project
) projects WHERE activity.pcode = project         


        
相关标签:
2条回答
  • 2021-02-14 10:44
    select
      pid,
      json_agg(json_build_object('code',code,'name',name))
    from
      ...
    group by
      pid
    
    0 讨论(0)
  • 2021-02-14 10:59
    SELECT pid from activity a, (
        select json_agg(project) from project where code = a.code 
    ) as p
    

    Something like that ...

    0 讨论(0)
提交回复
热议问题