SQL practice: JSON and JSONB: Documents Inside Rows
Chapter 37 · 8 questions · included in full access
Question 1 · easy
Solve it in your browserTurn each Adhesive product into a JSON object with keys name and price (from unit_price), in a column named product. Order by product_id.
Question 2 · easy
Solve it in your browserShow every product as a single JSON document of the whole row, in a column named doc, alongside its product_id. Order by product_id.
Question 3 · medium
Solve it in your browserFor every branch, build a JSON array of its employees’ names sorted alphabetically, in a column named team. Show branch_name too, ordered by branch_name.
Question 4 · medium
Solve it in your browserUsing to_jsonb over products, list the name of every product whose unit_price is above 3000, read out of the JSON rather than the column. Name the output column name and order by it.
Question 5 · medium
Solve it in your browserCount how many products are in the Adhesive category, using the JSON containment operator @> rather than a WHERE on the column. Name the count adhesives.
Question 6 · medium
Solve it in your browserTake the document {"city": "Delhi", "region": "North", "open": true} and return one row per key, with columns key and value. Order by key.
Question 7 · hard
Solve it in your browserBuild one JSON document per order containing the order_id and an array of the product names it contains, in a column named doc. Only include order 1, 2 and 3, ordered by order_id.
Question 8 · hard
Solve it in your browserWhich statement about json and jsonb is true?
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing