Practice Filtering

Practice writing queries to test your understanding of data filtering.

Filtering patterns questions

Let’s practice writing queries to strengthen your grasp of filtering patterns.

Generate a 30-day sales chart

Given the following structure of the Orders table:

Field

Type

OrderID

int

CustomerID

int

OrderDate

date

TotalAmount

decimal(10,2)

ShippedDate

date

DeliveryStatus

enum('Pending','Shipped','Delivered','Cancelled')

EmployeeID

int

CreatedAt

timestamp

ExpectedDeliveryDate

date

ActualDeliveryDate

date

LateDelivery

tinyint(1)

PaymentMethod

enum('Credit Card','PayPal','Cash on Delivery')

ReturnCount

int

FraudRisk

tinyint(1)

Where OrderID is the primary key and CustomerID is the foreign key from the Customers table referring to the customer who placed the order. The table contains information about the orders placed.

Write an SQL query that generates a 30-day daily sales report starting from March 1, 2025. Include:

  • ReportDate

  • TotalSales: Total order value for that day

  • Ensure all days are shown, even those with no orders (show 0 in such cases).

...