SQL practice: JSON and JSONB: Documents Inside Rows

Chapter 37 · 8 questions · included in full access

  1. Question 1 · easy

    Turn each Adhesive product into a JSON object with keys name and price (from unit_price), in a column named product. Order by product_id.

    Solve it in your browser
  2. Question 2 · easy

    Show every product as a single JSON document of the whole row, in a column named doc, alongside its product_id. Order by product_id.

    Solve it in your browser
  3. Question 3 · medium

    For 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.

    Solve it in your browser
  4. Question 4 · medium

    Using 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.

    Solve it in your browser
  5. Question 5 · medium

    Count how many products are in the Adhesive category, using the JSON containment operator @> rather than a WHERE on the column. Name the count adhesives.

    Solve it in your browser
  6. Question 6 · medium

    Take the document {"city": "Delhi", "region": "North", "open": true} and return one row per key, with columns key and value. Order by key.

    Solve it in your browser
  7. Question 7 · hard

    Build 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.

    Solve it in your browser
  8. Question 8 · hard

    Which statement about json and jsonb is true?

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing