Search⌘ K
AI Features

Question: Window Functions

Explore how to use window functions in SQL to analyze customer orders over time. Learn to calculate running totals and rank orders within each customer's history by joining Customers and Orders tables to produce detailed analytics outputs.

Question

Given the following structure of the Customers table:

Field

Type

CustomerID

int

CustomerName

varchar(50)

Email

varchar(50)

Phone

varchar(15)

Address

varchar(100)

LastLogin

date

CreatedAt

timestamp

CustomerTier

enum('New','Regular','VIP')

ReferralID

int

LoyaltyPoints

int

LastPurchaseDate

date

IsChurnRisk

tinyint(1)

Where, CustomerID is the primary key and ReferralID is self-referencing to CustomerID. The table contains information about customers. In the table, each customer is categorized by a CustomerTier to reflect their engagement level. The possible values are 'New''Regular', and 'VIP' ...