HAVING With SUM

#2 · 2 of 10Free sample
Question

HAVING With SUM

Find customers in the 'orders' table who have spent more than 500 in total. Return customer_id and the total_spent.
Tables
11 tables · 52 columns
customers7 cols
  • customer_idINTEGER
  • first_nameTEXT
  • last_nameTEXT
  • emailTEXT
  • cityTEXT
  • join_dateTEXT
  • phoneTEXT
departments3 cols
  • department_idINTEGER
  • department_nameTEXT
  • locationTEXT
employees6 cols
  • employee_idINTEGER
  • first_nameTEXT
  • last_nameTEXT
  • department_idINTEGER
  • hire_dateTEXT
  • salaryREAL
categories2 cols
  • category_idINTEGER
  • category_nameTEXT
products6 cols
  • product_idINTEGER
  • product_nameTEXT
  • category_idINTEGER
  • unit_priceREAL
  • stock_quantityINTEGER
  • creation_dateTEXT
orders6 cols
  • order_idINTEGER
  • customer_idINTEGER
  • employee_idINTEGER
  • order_dateTEXT
  • statusTEXT
  • total_amountREAL
order_items4 cols
  • order_idINTEGER
  • product_idINTEGER
  • quantityINTEGER
  • unit_priceREAL
suppliers4 cols
  • supplier_idINTEGER
  • supplier_nameTEXT
  • cityTEXT
  • products_suppliedTEXT
shipping_addresses6 cols
  • shipping_idINTEGER
  • order_idINTEGER
  • addressTEXT
  • cityTEXT
  • stateTEXT
  • postal_codeTEXT
inventory_movements5 cols
  • movement_idINTEGER
  • product_idINTEGER
  • change_quantityINTEGER
  • movement_dateTEXT
  • reasonTEXT
cities3 cols
  • city_idINTEGER
  • city_nameTEXT
  • stateTEXT
Loading the practice editor and dataset…
Your answer(autosaved)
query.sql
Loading editor…
Sign up to unlock

The reference answer is one click away.

Free account unlocks the reference answer, the explanation, and the GPT tutor on every exercise in the library.

  • Reference answer + explanation revealed after each attempt
  • GPT tutor for every problem
  • Progress saved on the platform
  • 1,598 graded exercises
  • Free forever — no credit card
All exercises in SQL: Filtering Aggregations With HAVING