A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.
SQL Skill — E-Commerce Database
Database Schema
customers (id, name, email, city, country, signup_date)
products (id, name, category, price, stock)
orders (id, customer_id, order_date, status)
order_items (id, order_id, product_id, quantity, unit_price)
Column notes
orders.status— one of:pending,processing,shipped,delivered,cancelledproducts.category— one of:Electronics,Clothing,Books,Home & Garden,Sports- All dates are stored as ISO strings:
YYYY-MM-DD - Revenue for an item =
quantity * unit_price
Common Query Patterns
Total revenue per order
SELECT order_id, SUM(quantity * unit_price) AS total
FROM order_items
GROUP BY order_id;
Top customers by spend
SELECT c.name, SUM(oi.quantity * oi.unit_price) AS total_spend
FROM customers c
JOIN orders o ON c.id = o.customer_id
JOIN order_items oi ON o.id = oi.order_id
WHERE o.status != 'cancelled'
GROUP BY c.id, c.name
ORDER BY total_spend DESC
LIMIT 10;
Best-selling products (by quantity)
SELECT p.name, SUM(oi.quantity) AS units_sold
FROM products p
JOIN order_items oi ON p.id = oi.product_id
GROUP BY p.id, p.name
ORDER BY units_sold DESC;
Revenue by category
SELECT p.category, SUM(oi.quantity * oi.unit_price) AS revenue
FROM products p
JOIN order_items oi ON p.id = oi.product_id
JOIN orders o ON oi.order_id = o.id
WHERE o.status != 'cancelled'
GROUP BY p.category
ORDER BY revenue DESC;
Orders in a date range
SELECT * FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-03-31';
Orders by status count
SELECT status, COUNT(*) AS count
FROM orders
GROUP BY status
ORDER BY count DESC;
SQLite Syntax Rules
- String literals use single quotes:
WHERE city = 'London' - Date functions: Use
strftime('%Y', order_date)to extract year;DATE('now')for today - LIKE wildcards:
%matches any sequence,_matches one character —WHERE name LIKE '%phone%' - No ILIKE: SQLite
LIKEis case-insensitive for ASCII by default - Integer division: Cast explicitly —
CAST(a AS REAL) / bfor decimal results - No RIGHT JOIN: Rewrite as LEFT JOIN with tables swapped
- LIMIT always at end: Place
LIMITafterORDER BY - Subqueries: Supported — wrap in parentheses with an alias:
FROM (SELECT ...) AS sub
Safety Rules
- Only write
SELECTqueries — neverINSERT,UPDATE,DELETE, orDROP - Always alias aggregated columns for clarity:
SUM(...) AS revenue - Check column names against the schema — never assume a column exists