You are a data analyst expert in SQL. Analyze this PostgreSQL database: Table:…
- User
You are a data analyst expert in SQL. Analyze this PostgreSQL database:
Table: retail_ingest_data Available Columns with Types: transaction_id (text) date (text) customer_id (text) gender (text) age (text) product_category (text) quantity (numeric) price_per_unit (text) total_amount (numeric)
Sample Data:
transaction_id date customer_id gender age product_category quantity price_per_unit total_amount 1 2023-11-24 CUST001 Male 34 Beauty 3 50 150 2 2023-02-27 CUST002 Female 26 Clothing 2 500 1000 3 2023-01-13 CUST003 Male 50 Electronics 1 30 30 CRITICAL RULES:
- ONLY use columns from the list above
- If the available columns are insufficient to answer the question, clearly state that
- Keep answers concise and focused
- For numeric calculations, CAST string columns to NUMERIC using CAST(column_name AS NUMERIC)
- Table name is exactly 'retail_ingest_data'
VISUALIZATION RULES:
- Only suggest bar, line, or pie charts
- ONLY use column names that exist in the data
- Bar charts: For comparing categories or groups
- Line charts: For time-based trends
- Pie charts: For showing composition/distribution
Example Responses:
-
Time-based Question: "Show monthly sales trend" { "sql_query": "SELECT DATE_TRUNC('month', date::timestamp) as month, SUM(CAST(total_amount AS NUMERIC)) as total_sales FROM retail_ingest_data GROUP BY month ORDER BY month", "answer": "Monthly sales show an upward trend with peak in December at $50,000", "visualization": { "type": "line", "x_axis": "month", "y_axis": "total_sales", "title": "Monthly Sales Trend", "description": "Line chart shows sales progression over time" } }
- Assistantjson
{ "sql_query": "SELECT product_category, SUM(CAST(total_amount AS NUMERIC)) as total_sales FROM retail_ingest_data WHERE product_category IN ('Electronics', 'Beauty') GROUP BY product_category", "answer": "The total sales for Electronics and Beauty categories are compared to see which has higher sales.", "visualization": { "type": "bar", "x_axis": "product_category", "y_axis": "total_sales", "title": "Sales Comparison of Electronics and Beauty", "description": "Bar chart effectively compares total sales between Electronics and Beauty categories" } }