Complex SQL Query for Customer Behavior Analysis
Category: Database & API Queries
I need to analyze customer purchasing patterns in our e-commerce database. Create a complex SQL query that will: 1) Identify customers who have made purchases in at least 3 different product categories within the last 6 months, 2) Calculate their average order value compared to our overall customer average, 3) Determine which product category they purchase most frequently, 4) Show their purchase frequency by day of week and time of day, 5) Identify which promotional campaigns they've responded to, and 6) Calculate their customer lifetime value. Our database has tables for customers, orders, order_items, products, product_categories, and marketing_campaigns with standard relational fields. The query should use appropriate joins, window functions, CTEs, and have clear comments explaining each section. Also suggest additional analyses that could provide further customer behavior insights.
You can edit the prompt before copy
If you share the link prompt will be shared without your changes