You are given a Store table containing bill information for customers. Each row represents one bill with its associated customer and amount.
Table: Store
| Column Name | Type |
|---|---|
| bill_id | int |
| customer_id | int |
| amount | int |
bill_id is the primary key for this table. Each row contains the amount of one bill and the customer who made the purchase.
Write a SQL query to report the number of customers who had at least one bill with an amount strictly greater than 500.
Table Schema
| Column Name | Type | Description |
|---|---|---|
bill_id
PK
|
int | Primary key, unique identifier for each bill |
customer_id
|
int | ID of the customer who made the purchase |
amount
|
int | Amount of the bill in dollars |
Input & Output
| bill_id | customer_id | amount |
|---|---|---|
| 1 | 1 | 800 |
| 2 | 2 | 300 |
| 3 | 3 | 700 |
| 4 | 1 | 600 |
| rich_count |
|---|
| 2 |
Customer 1 has bills of $800 and $600 (both > 500). Customer 2 has a bill of $300 (≤ 500). Customer 3 has a bill of $700 (> 500). Only customers 1 and 3 qualify as 'rich customers', so the answer is 2.
| bill_id | customer_id | amount |
|---|---|---|
| 1 | 1 | 200 |
| 2 | 2 | 450 |
| 3 | 3 | 500 |
| rich_count |
|---|
| 0 |
All bills are ≤ $500. Since we need amounts strictly greater than 500, no customers qualify as rich customers. The result is 0.
| bill_id | customer_id | amount |
|---|---|---|
| 1 | 1 | 1000 |
| 2 | 2 | 750 |
| 3 | 3 | 600 |
| rich_count |
|---|
| 3 |
All customers have at least one bill > $500: Customer 1 ($1000), Customer 2 ($750), and Customer 3 ($600). The result is 3.
Constraints
-
1 ≤ bill_id ≤ 1000 -
1 ≤ customer_id ≤ 1000 -
0 ≤ amount ≤ 10000