w3resource
SQL exercises

SQL Exercises: Find customer details (within a specific range) and purchase amount more than a specific amount

SQL Aggregate Functions: Exercise-16 with Solution

Write a SQL statement to display customer details (ID and purchase amount) whose IDs are within the range 3002 and 3007 and highest purchase amount is more than 1000.

Sample table: orders


Sample Solution:

SELECT customer_id,MAX(purch_amt) 
FROM orders 
WHERE customer_id BETWEEN 3002 and 3007 
GROUP BY customer_id 
HAVING MAX(purch_amt)>1000;

Output of the Query:

customer_id	max
3002		5760.00
3007		2400.60
3004		1983.43

Explanation:

Syntax of display customer details with specified range

Pictorial presentation :

Result of display customer details with specified range

Query Visualization:

Duration:

Query visualization of Find customer details (within a specific range) and purchase amount more than a specific amount - Duration

Rows:

Query visualization of Find customer details (within a specific range) and purchase amount more than a specific amount - Rows

Cost:

Query visualization of Find customer details (within a specific range) and purchase amount more than a specific amount - Cost

 

Practice Online


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a SQL statement to find the highest purchase amount with their ID, for only those customers whose ID is within the range 3002 and 3007.
Next: Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen whose ID is within the range 5003 and 5008.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming