ComeçarComece de graça

Bucketing users by orders

Dave is repeating his bucketing analysis on orders to have a more complete profile of each group. He determined that 8 orders is a good cut-off for the low-orders group, and 15 is a good cut-off for the medium orders group.

Send Dave a table of each order group and how many users are in it.

Este exercício faz parte do curso

Analyzing Business Data in SQL

Ver curso

Instruções do exercício

  • Store each user ID and its count of orders in a CTE named user_orders.
  • Set the cut-off point for the low-orders bucket to 8 orders, and set the cut-off point for the mid-orders bucket to 15 orders.
  • Count the distinct users in each bucket.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

-- Store each user's count of orders in a CTE named user_orders
___ ___ ___ (
  SELECT
    ___,
    ___ AS orders
  FROM orders
  GROUP BY ___)

SELECT
  -- Write the conditions for the three buckets
  CASE
    WHEN ___ THEN 'Low-orders users'
    WHEN ___ THEN 'Mid-orders users'
    ELSE 'High-orders users'
  END AS order_group,
  -- Count the distinct users in each bucket
  ___ AS users
FROM user_orders
GROUP BY order_group;
Editar e executar o código