Solve hundreds of SQL problems ranging from beginner to advanced levels...
Get StartedSelect Topics
Select Statement
Where Clause
Joins Up to 4 Tables
Subqueries
Many More
Select Level
Beginner
Intermediate
Proficient
Expert
Many More
Select Database
Finance
Sales
HealthCare
IT
Many More
Write a query to retrieve all transactions ?greater than $1000 from the last month, and ?only include transactions from customers ?who have made more than 5 purchases in ?total.
SELECT * FROM Transactions
WHERE Amount > 1000
AND TransactionDate >= DATEADD(month, -1, GETDATE())
AND CustomerID IN
( SELECT CustomerID FROM Customers
WHERE TotalPurchases > 5 );
Query executed successfully and retrieved the expected results.
Positive Aspect:
The query correctly filters transactions greater than $1000 using WHERE Amount > 1000.
It accurately retrieves transactions from the last month with TransactionDate >= DATEADD(month, -1, GETDATE()).
The subquery within IN clause successfully filters customers who have made more than 5 purchases using SELECT CustomerID FROM Customers WHERE TotalPurchases > 5.
Suggestions for Improvement:
Consider using table aliases to enhance readability. For example:
SELECT t.* FROM Transactions t
WHERE t.Amount > 1000
AND t.TransactionDate >= DATEADD(month, -1, GETDATE())
AND t.CustomerID IN
( SELECT c.CustomerID FROM Customers C
WHERE c.TotalPurchases > 5 );
Are you eager to enhance your SQL skills or just starting out in database management? Our online SQL Practice platform is designed specifically for beginners, offering you a structured and supportive environment to learn and practice SQL effectively.
Access to basic SQL practice questions and feedback.
$0
Features:
Basic SQL Questions
Limited Database Access
Basic Feedback
Unlimited access to all features, questions, and detailed feedback.
Coming Soon
Features:
Unlimited SQL Questions
Access to All Databases
Detailed Feedback