Filter Orders by Date Range
Beginner Mode
Objective
Construct a SQL query to fetch the order_id, customer_name, order_date, and total_amount from the orders table. The query should retrieve only those orders placed between January 1, 2023, and June 30, 2023, and the results must be ordered by the order_date in ascending order.
Additional information
The orders table:
| Column | Type | Description |
|---|---|---|
| order_id | INTEGER | Unique identifier for each order |
| customer_name | VARCHAR | Name of the customer who placed the order |
| order_date | DATE | Date when the order was placed |
| total_amount | DECIMAL | Total monetary value of the order |
- Ensure that the
order_datefalls inclusively between '2023-01-01' and '2023-06-30'. - The output should list the orders sorted from the earliest to the latest based on the
order_date. - Assume all dates are in the 'YYYY-MM-DD' format.
Examples
Example 1:
Output:
Input:
| orders | |||
|---|---|---|---|
| customer_name | order_date | order_id | total_amount |
| John Smith | 2023-01-15 | 1 | 299.99 |
| Alice Brown | 2022-12-25 | 2 | 150.5 |
| Mike Johnson | 2023-03-10 | 3 | 445.75 |
| Sarah Wilson | 2023-07-05 | 4 | 199.99 |
| Tom Davis | 2023-05-22 | 5 | 678.25 |
| customer_name | order_date | order_id | total_amount |
|---|---|---|---|
| John Smith | 2023-01-15 | 1 | 299.99 |
| Mike Johnson | 2023-03-10 | 3 | 445.75 |
| Tom Davis | 2023-05-22 | 5 | 678.25 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Google