<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>sql on Pieces &amp; Perspective Blog</title><link>https://xbns.netlify.app/tags/sql/</link><description>Recent content in sql on Pieces &amp; Perspective Blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 18 Nov 2020 00:00:00 +0000</lastBuildDate><atom:link href="https://xbns.netlify.app/tags/sql/index.xml" rel="self" type="application/rss+xml"/><item><title>JSON Function - json_build_object</title><link>https://xbns.netlify.app/posts/json-build-object/</link><pubDate>Wed, 18 Nov 2020 00:00:00 +0000</pubDate><guid>https://xbns.netlify.app/posts/json-build-object/</guid><description>Explanation(TODO:10) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 SELECT o.id,o.total_cost,o.managed_by, CASE WHEN count(ox) = 0 THEN ARRAY[]::json[] ELSE array_agg(ox.order_item) END AS order_items FROM fasiba.orders o LEFT OUTER JOIN ( SELECT oid2.orders_id, json_build_object(&amp;#39;input_name&amp;#39;,i.name,&amp;#39;quantity&amp;#39;,oid2.quantity,&amp;#39;unit_cost&amp;#39;,oid2.unit_cost,&amp;#39;total_cost&amp;#39;,oid2.total_cost) as order_item FROM fasiba.orders_input_detail oid2 left join fasiba.input i on i.id = oid2.input_pack_detail_id ORDER BY oid2.input_pack_id ) ox ON o.id = ox.orders_id WHERE o.status =&amp;#39;DELIVERED&amp;#39; GROUP BY o.id limit 10 REFERENCE For a more elaborative example have a look at the link below.</description></item></channel></rss>