Advanced

4. User_Profile

Extended user attributes

CREATE TABLE User_Profile (
    profile_id INT IDENTITY(1,1) PRIMARY KEY,
    user_id INT UNIQUE NOT NULL,
    email VARCHAR(200),
    phone VARCHAR(20),
    created_at DATETIME DEFAULT GETDATE(),
    FOREIGN KEY (user_id) REFERENCES [User](userid)
);

5. User_Address

Multiple addresses per user

CREATE TABLE User_Address (
    address_id INT IDENTITY(1,1) PRIMARY KEY,
    user_id INT NOT NULL,
    address_line VARCHAR(300),
    city VARCHAR(100),
    state VARCHAR(100),
    country VARCHAR(100),
    pincode VARCHAR(20),
    FOREIGN KEY (user_id) REFERENCES [User](userid)
);

6. User_Login_History

Tracks login behavior


7. Product_Category


8. Product_Category_Map

Many-to-many: products ↔ categories


9. Product_Inventory


10. Product_Price_History


11. Order_Header

Logical order abstraction


12. Order_Item


13. Payment


14. Shipment


15. Review


16. Wishlist


17. Wishlist_Item


18. Coupon


19. Order_Coupon


20. Audit_Log


Sample Entrie

Understood. Below is a clean, FK-safe data seeding script with 10 rows per table, using multi-row INSERTs (industry-standard practice). This keeps it readable while still giving you 10 records per table.

Assumptions • IDENTITY columns auto-generate IDs • IDs are referenced sequentially (1–10) • Script is executed in order


TABLE 1 – User (10 rows)


TABLE 2 – Product (10 rows)


TABLE 3 – User_Purchase (10 rows)


TABLE 4 – User_Profile (10 rows)


TABLE 5 – User_Address (10 rows)


TABLE 6 – User_Login_History (10 rows)


TABLE 7 – Product_Category (10 rows)


TABLE 8 – Product_Category_Map (10 rows)


TABLE 9 – Product_Inventory (10 rows)


TABLE 10 – Product_Price_History (10 rows)


TABLE 11 – Order_Header (10 rows)


TABLE 12 – Order_Item (10 rows)


TABLE 13 – Payment (10 rows)


TABLE 14 – Shipment (10 rows)


TABLE 15 – Review (10 rows)


TABLE 16 – Wishlist (10 rows)


TABLE 17 – Wishlist_Item (10 rows)


TABLE 18 – Coupon (10 rows)


TABLE 19 – Order_Coupon (10 rows)


TABLE 20 – Audit_Log (10 rows)


Assginments

Assignment 1: Customer 360 View

Objective: Create a query that shows a single consolidated view per user, including:

  • username

  • city

  • email

  • total number of orders

  • total amount spent

  • last purchase date

Skills tested: joins, aggregation, grouping


Assignment 2: Revenue & Fulfillment Analysis

Objective: List all orders with:

  • order id

  • username

  • order status

  • payment status

  • shipment carrier

  • delivery date

Filter only orders that are paid but not yet delivered.

Skills tested: multi-table joins, filtering, business logic


Assignment 3: Product Performance Dashboard

Objective: For each product, calculate:

  • total quantity sold

  • total revenue

  • average rating

  • current stock quantity

Sort products by total revenue descending.

Skills tested: joins, aggregates, left joins, ordering


Assignment 4: Marketing Effectiveness (Coupons)

Objective: Analyze coupon usage and show:

  • coupon code

  • number of orders using it

  • total revenue generated from those orders

  • average order value per coupon

Skills tested: many-to-many joins, aggregation


Assignment 5: User Engagement & Behavior

Objective: Identify users who:

  • logged in at least 3 times

  • placed at least 1 order

  • added at least 1 product to wishlist

  • wrote at least 1 review

Return username and counts for each activity.

Skills tested: subqueries / CTEs, HAVING, behavioral analysis


Assignment 6: High-Value Customers (HVC)

Objective: Identify users who:

  • have placed more than 1 order, and

  • whose total spending is above the average user spending.

Return:

  • username

  • city

  • total orders

  • total spending

Skills tested: aggregation, subqueries / CTEs, HAVING


Assignment 7: Order-to-Delivery Efficiency

Objective: Calculate the average delivery time (in days) for each carrier.

Return:

  • carrier

  • total shipments

  • average delivery days

Exclude orders that are not yet delivered.

Skills tested: date functions, joins, filtering


Assignment 8: Product Price Volatility

Objective: For each product, calculate:

  • minimum historical price

  • maximum historical price

  • price fluctuation percentage

Fluctuation % = [ \frac{max_price - min_price}{min_price} \times 100 ]

Skills tested: aggregation, derived metrics


Assignment 9: User Purchase Funnel

Objective: For each user, show whether they have:

  • registered (exists in User)

  • placed an order

  • completed payment

  • received shipment

Return one row per user with Yes / No flags.

Skills tested: LEFT JOINs, CASE statements


Assignment 10: Cross-Sell Opportunity Detection

Objective: Find product pairs that are:

  • purchased by the same users, and

  • appear together in different orders by those users.

Return:

  • product A

  • product B

  • number of common users

Skills tested: self-joins, DISTINCT logic, analytics reasoning


Assignment 11: Repeat Purchase Behavior

Objective: Identify users who have purchased the same product more than once across different orders.

Skills tested: joins, grouping, HAVING


Assignment 12: Revenue Leakage Detection

Objective: Find orders where:

  • payment status is Success

  • but no shipment record exists

Return order id, user, payment amount.

Skills tested: LEFT JOIN, NULL checks


Assignment 13: Inventory Risk Analysis

Objective: List products where:

  • current stock quantity is less than total quantity sold

Skills tested: aggregation, joins, comparison logic


Assignment 14: Review Bias Detection

Objective: Find users whose average rating is:

  • at least 1 point higher than the overall average rating

Skills tested: aggregation, subqueries


Assignment 15: Time-to-Purchase Analysis

Objective: For each user, calculate the number of days between account creation (User_Profile.created_at) and their first order date.

Skills tested: date arithmetic, MIN aggregation


Assignment 16: Coupon Effectiveness Over Time

Objective: Show monthly coupon usage with:

  • month

  • number of orders

  • total discounted revenue (assume discount applies to full order amount)

Skills tested: time grouping, joins, calculations


Assignment 17: Product Cannibalization

Objective: Find products where:

  • a price drop (from Product_Price_History) is followed by

  • a measurable increase in quantity sold

Skills tested: temporal joins, analytics reasoning


Assignment 18: Dormant Users

Objective: Identify users who:

  • have registered

  • but have not placed any order in the last 90 days

Skills tested: date filters, anti-joins


Assignment 19: End-to-End Order Trace

Objective: Create a query that shows, per order:

  • user

  • products purchased

  • payment status

  • shipment status

  • coupon used (if any)

Skills tested: multi-table joins, optional relationships


Assignment 20: Customer Lifetime Value (CLV)

Objective: Calculate CLV per user using:

Skills tested: aggregation, derived metrics


Below are 10 more advanced SQL assignments (Assignments 21–30) built strictly on your existing 20-table schema. These focus on analytics depth, reasoning, and production-style querying.


Assignment 21: Order Completion Rate per User

Objective: For each user, calculate:

  • total orders placed

  • total orders delivered

  • order completion rate (%)

Skills tested: conditional aggregation, joins


Assignment 22: Revenue by Payment Method

Objective: Show:

  • payment method

  • total number of payments

  • total revenue

  • average payment amount

Skills tested: grouping, aggregation


Assignment 23: Products with No Reviews but High Sales

Objective: Identify products that:

  • have zero reviews

  • but have total revenue above the average product revenue

Skills tested: LEFT JOIN, aggregation, subqueries


Assignment 24: User Order Interval Analysis

Objective: For each user, calculate the average number of days between consecutive orders.

Skills tested: window functions (LAG), date arithmetic


Assignment 25: Carrier Performance Consistency

Objective: Find carriers where:

  • delivery time variance is low (stable delivery)

  • average delivery time is under 5 days

Skills tested: aggregation, variance/stddev functions


Assignment 26: Category Revenue Contribution

Objective: For each product category, calculate:

  • total revenue

  • percentage contribution to overall revenue

Skills tested: many-to-many joins, percentage calculation


Assignment 27: Users Who Abandoned Payment

Objective: Identify users who:

  • placed orders

  • but have only failed or pending payments

Skills tested: joins, HAVING logic


Assignment 28: Most Influential Reviewers

Objective: Find users whose reviews are:

  • above the overall average rating

  • and who reviewed at least 3 products

Skills tested: aggregation, filtering


Assignment 29: Inventory Turnover Ratio

Objective: For each product, calculate the inventory turnover ratio:

Skills tested: aggregation, business metrics


Assignment 30: End-of-Month Revenue Spike Detection

Objective: Detect months where:

  • revenue in the last 5 days of the month

  • exceeds the first 5 days by more than 30%

Skills tested: time-based grouping, conditional aggregation


Below are 10 expert-level SQL assignments (Assignments 31–40) built strictly on your existing 20-table schema. These emphasize advanced analytics, temporal reasoning, and production-grade thinking.


Assignment 31: Customer Churn Indicator

Objective: Identify users whose last order date is older than 120 days and who have no pending shipments.

Skills tested: date filters, anti-joins


Assignment 32: Revenue Concentration Risk

Objective: Calculate the percentage of total revenue contributed by the top 10% of users.

Skills tested: window functions, percentile logic


Assignment 33: Product Seasonality Detection

Objective: Find products whose sales spike (≥40% increase) in any month compared to their own average monthly sales.

Skills tested: time grouping, comparisons, subqueries


Assignment 34: Order Processing Bottleneck

Objective: Identify orders where:

  • payment was successful

  • but shipment was created more than 3 days later

Skills tested: date arithmetic, joins


Assignment 35: User Loyalty Score

Objective: Compute a loyalty score per user using: [ \text{Score} = (2 \times \text{Orders}) + (1 \times \text{Reviews}) + (3 \times \text{Wishlist Items}) ]

Skills tested: multi-table aggregation


Assignment 36: Price Sensitivity Analysis

Objective: For each product, analyze whether:

  • a price reduction

  • leads to a statistically significant increase in quantity sold (before vs after).

Skills tested: temporal segmentation, analytical reasoning


Assignment 37: Fulfillment SLA Compliance

Objective: Calculate the SLA compliance rate per carrier:

  • Delivered within ≤5 days

Skills tested: conditional aggregation, joins


Assignment 38: Cross-Category Buyer Analysis

Objective: Identify users who purchased products from at least 3 different categories.

Skills tested: many-to-many joins, DISTINCT counts


Assignment 39: Revenue Recovery Opportunity

Objective: Find orders that:

  • failed payment initially

  • but later succeeded Return recovery rate.

Skills tested: sequencing, status transitions


Assignment 40: End-to-End Conversion Funnel

Objective: Build a funnel showing:

  • registered users

  • users with orders

  • users with successful payments

  • users with delivered shipments

Skills tested: funnel analytics, LEFT JOIN logic


Assignment 41: Customer Purchase Momentum

Objective: For each user, determine whether their purchase frequency is accelerating, stable, or declining over time.

Skills tested: window functions, trend analysis


Assignment 42: Revenue Dependency Index

Objective: For each product, calculate what percentage of its revenue comes from repeat buyers vs first-time buyers.

Skills tested: cohort analysis, joins, aggregation


Assignment 43: Order Fragmentation Risk

Objective: Identify users who place many small orders instead of fewer large ones (e.g., average order value < overall average but order count > overall average).

Skills tested: comparative aggregation


Assignment 44: Supply Chain Stress Detection

Objective: Detect products where:

  • inventory is low

  • sales velocity is high

  • shipment delays are frequent

Skills tested: multi-domain joins, business logic


Assignment 45: Review Impact on Sales

Objective: Analyze whether products receive higher sales after positive reviews (rating ≥ 4).

Skills tested: temporal joins, before/after comparison


Assignment 46: Coupon Abuse Detection

Objective: Identify users who:

  • repeatedly use high-discount coupons

  • across multiple orders

  • within a short time window.

Skills tested: joins, filtering, time windows


Assignment 47: Multi-Channel Payment Reliability

Objective: For each payment method, calculate:

  • success rate

  • average retry count per order (inferred from payment attempts)

Skills tested: aggregation, inferred metrics


Assignment 48: Product Portfolio Risk

Objective: Find categories where:

  • revenue is concentrated in ≤2 products

  • contributing ≥70% of category revenue.

Skills tested: ranking, cumulative sums


Assignment 49: Silent Drop-Off Detection

Objective: Identify users who:

  • added items to wishlist

  • logged in multiple times

  • but never completed a purchase.

Skills tested: anti-joins, behavioral analysis


Assignment 50: Executive KPI Snapshot

Objective: Produce a single query that outputs:

  • total users

  • active users (last 30 days)

  • total revenue

  • average order value

  • delivery success rate

  • top product by revenue

Skills tested: multi-metric aggregation, executive reporting


Tind: f37327ac-ff45-407e-8de2-b200851f369e

Last updated