<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rosy's SQL Practice - Amazon Interview Prep</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #232f3e 0%, #37475a 100%);
            min-height: 100vh;
            padding: 20px;
            color: #333;
        }
        .container {
            max-width: 900px;
            margin: 0 auto;
        }
        .card {
            background: white;
            border-radius: 12px;
            padding: 30px;
            margin-bottom: 20px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
        }
        h1 {
            color: #232f3e;
            margin-bottom: 10px;
            font-size: 2rem;
        }
        h2 {
            color: #232f3e;
            margin-bottom: 15px;
            font-size: 1.3rem;
            border-bottom: 2px solid #ff9900;
            padding-bottom: 8px;
        }
        h3 {
            color: #37475a;
            margin: 15px 0 10px 0;
            font-size: 1.1rem;
        }
        .subtitle {
            color: #666;
            margin-bottom: 20px;
            font-size: 1.1rem;
        }
        .btn {
            display: inline-block;
            background: linear-gradient(135deg, #ff9900 0%, #ffad33 100%);
            color: #232f3e;
            padding: 15px 40px;
            border-radius: 8px;
            text-decoration: none;
            font-size: 1.1rem;
            font-weight: 600;
            transition: transform 0.2s, box-shadow 0.2s;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 30px rgba(255, 153, 0, 0.4);
        }
        .btn-secondary {
            background: linear-gradient(135deg, #37475a 0%, #4a5568 100%);
            color: white;
        }
        .info {
            margin-top: 20px;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 8px;
        }
        .info ul {
            margin-left: 20px;
            color: #666;
        }
        .info li {
            margin: 8px 0;
        }
        code {
            background: #e9ecef;
            padding: 2px 8px;
            border-radius: 4px;
            font-family: 'Monaco', 'Consolas', monospace;
            font-size: 0.9em;
        }
        .schema-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-top: 15px;
        }
        .schema-table {
            background: #f1f3f4;
            padding: 15px;
            border-radius: 8px;
            border-left: 4px solid #ff9900;
        }
        .schema-table h4 {
            color: #232f3e;
            margin-bottom: 8px;
            font-size: 0.95rem;
        }
        .schema-table p {
            color: #666;
            font-size: 0.85rem;
            margin: 0;
        }
        .row-count {
            color: #ff9900;
            font-weight: 600;
        }
        .tag {
            display: inline-block;
            background: #232f3e;
            color: #ff9900;
            padding: 3px 10px;
            border-radius: 4px;
            font-size: 0.8rem;
            margin-right: 5px;
            margin-bottom: 5px;
        }
        .tag-olap {
            background: #ff9900;
            color: #232f3e;
        }
        .quiz-topics {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 10px;
        }
        .topic {
            background: #e8f4f8;
            color: #0066c0;
            padding: 5px 12px;
            border-radius: 20px;
            font-size: 0.85rem;
        }
        footer {
            text-align: center;
            color: rgba(255,255,255,0.7);
            padding: 20px;
            font-size: 0.9rem;
        }
        footer a {
            color: #ff9900;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="card">
            <h1>Rosy's SQL Practice</h1>
            <p class="subtitle">Amazon Data & Reporting Analyst Interview Prep</p>

            <a href="/adminer/" class="btn">Open SQL Editor</a>
            <a href="/adminer/?sql=" class="btn btn-secondary">Open SQL Worksheet</a>

            <div class="info">
                <h3>Login Credentials</h3>
                <ul>
                    <li><strong>System:</strong> MySQL</li>
                    <li><strong>Server:</strong> db</li>
                    <li><strong>Username:</strong> rosy</li>
                    <li><strong>Password:</strong> <em>(ask Guy!)</em></li>
                    <li><strong>Database:</strong> practice</li>
                </ul>
            </div>
        </div>

        <div class="card">
            <h2>OLTP Tables (Normalized)</h2>
            <p>Transactional tables - the "source of truth" with minimal data duplication.</p>

            <div class="schema-grid">
                <div class="schema-table">
                    <h4>warehouses</h4>
                    <p><span class="row-count">10</span> rows</p>
                    <p>Distribution centers</p>
                </div>
                <div class="schema-table">
                    <h4>suppliers</h4>
                    <p><span class="row-count">8</span> rows</p>
                    <p>Product vendors</p>
                </div>
                <div class="schema-table">
                    <h4>products</h4>
                    <p><span class="row-count">48</span> rows</p>
                    <p>SKU catalog</p>
                </div>
                <div class="schema-table">
                    <h4>customers</h4>
                    <p><span class="row-count">200</span> rows</p>
                    <p>Customer records</p>
                </div>
                <div class="schema-table">
                    <h4>drivers</h4>
                    <p><span class="row-count">116</span> rows</p>
                    <p>Delivery drivers</p>
                </div>
                <div class="schema-table">
                    <h4>vehicles</h4>
                    <p><span class="row-count">153</span> rows</p>
                    <p>Fleet vehicles</p>
                </div>
                <div class="schema-table">
                    <h4>shipments</h4>
                    <p><span class="row-count">~55K</span> rows</p>
                    <p>Delivery records</p>
                </div>
                <div class="schema-table">
                    <h4>shipment_conditions</h4>
                    <p><span class="row-count">~220K</span> rows</p>
                    <p>GPS/IoT time-series</p>
                </div>
                <div class="schema-table">
                    <h4>inventory_snapshots</h4>
                    <p><span class="row-count">~50K</span> rows</p>
                    <p>Weekly stock levels</p>
                </div>
                <div class="schema-table">
                    <h4>orders</h4>
                    <p><span class="row-count">~142K</span> rows</p>
                    <p>Customer orders</p>
                </div>
                <div class="schema-table">
                    <h4>order_items</h4>
                    <p><span class="row-count">~424K</span> rows</p>
                    <p>Order line items</p>
                </div>
            </div>
        </div>

        <div class="card">
            <h2>OLAP Tables (Denormalized)</h2>
            <p>Pre-aggregated reporting tables - faster queries, but derived from OLTP data.</p>

            <div class="schema-grid">
                <div class="schema-table">
                    <span class="tag tag-olap">OLAP</span>
                    <h4>daily_delivery_metrics</h4>
                    <p>On-time %, delays, risk by warehouse/day</p>
                </div>
                <div class="schema-table">
                    <span class="tag tag-olap">OLAP</span>
                    <h4>weekly_sales_summary</h4>
                    <p>Revenue, quantity, customers by product/week</p>
                </div>
                <div class="schema-table">
                    <span class="tag tag-olap">OLAP</span>
                    <h4>monthly_inventory_report</h4>
                    <p>Stock levels, reorder alerts by month</p>
                </div>
            </div>
        </div>

        <div class="card">
            <h2>Practice Quiz</h2>
            <p>25 questions covering common SQL interview topics, plus bonus OLTP vs OLAP comparisons!</p>

            <div class="quiz-topics">
                <span class="topic">SELECT & WHERE</span>
                <span class="topic">JOINs</span>
                <span class="topic">GROUP BY</span>
                <span class="topic">Aggregations</span>
                <span class="topic">Time-Series</span>
                <span class="topic">Subqueries</span>
                <span class="topic">CASE Statements</span>
                <span class="topic">Window Functions</span>
                <span class="topic">Period Comparisons</span>
            </div>

            <div class="info" style="margin-top: 20px;">
                <h3>How to Access the Quiz</h3>
                <p>The quiz is stored as SQL comments in the database. Run this query:</p>
                <code style="display: block; margin-top: 10px; padding: 10px;">
                    SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'practice';
                </code>
                <p style="margin-top: 15px;">Or download the quiz file: <a href="https://github.com/shitchell/rtdb/blob/main/init/005-practice-quiz.sql" target="_blank">005-practice-quiz.sql</a></p>
            </div>
        </div>

        <div class="card">
            <h2>Quick Reference</h2>

            <h3>Sample Queries to Try</h3>
            <div class="info">
                <p><strong>1. See all tables:</strong></p>
                <code>SHOW TABLES;</code>

                <p style="margin-top: 15px;"><strong>2. View table structure:</strong></p>
                <code>DESCRIBE shipments;</code>

                <p style="margin-top: 15px;"><strong>3. Basic JOIN:</strong></p>
                <code>SELECT o.id, c.name, o.total_amount FROM orders o JOIN customers c ON o.customer_id = c.id LIMIT 10;</code>

                <p style="margin-top: 15px;"><strong>4. Aggregation:</strong></p>
                <code>SELECT category, COUNT(*), SUM(unit_cost) FROM products GROUP BY category;</code>

                <p style="margin-top: 15px;"><strong>5. Time-series (OLAP):</strong></p>
                <code>SELECT report_date, warehouse_name, on_time_count, late_count FROM daily_delivery_metrics WHERE report_date >= '2024-01-01' LIMIT 20;</code>
            </div>
        </div>
    </div>

    <footer>
        <p>Data based on <a href="https://www.kaggle.com/datasets/dataseengineer/logistics-and-supply-chain-dataset" target="_blank">Southern California Logistics Dataset</a> | 2 years of synthetic supply chain data</p>
        <p>Good luck with your Amazon interview, Rosy! You've got this! </p>
    </footer>
</body>
</html>
