{"question":"How many repeat purchases were made in Q1 2024?","ground_truth_query":"SELECT SUM(CASE WHEN order_count > 1 THEN order_count - 1 ELSE 0 END) AS repeat_purchases FROM ( SELECT customer_id, COUNT(DISTINCT order_id) AS order_count FROM order_values WHERE order_year = 2024 AND order_quarter = 1 GROUP BY customer_id ) AS subquery;","execution_status_gtu":"Success","execution_result_gtu":" repeat_purchases\n0 93","llama_sqlcoder_3_few_promp":"SELECT COUNT(DISTINCT CASE WHEN rto_status = 'true' THEN order_id END) AS repeat_orders FROM order_values WHERE order_quarter = 1 AND order_year = 2024;","execution_status_llama":"Success","execution_result_llama":" repeat_orders\n0 6","messages":[{"content":"\nYou are a SQL expert in Mysql. As a SQL expert, your job is to answer data related questions from the business team accurately by writing SQL queries. Refer to the provided database schema for tables and columns. Do not correct spelling mistakes in the schema.\n\nPlease generate only read\/SELECT queries for data safety. If a question cannot be answered using a SELECT operation, it should not be addressed.\nRefer the sample queries to see how date filters and calculations are done. Pay high attention on sample queries that seem most relevant to user question.\n\nFormat your responses as JSON, including the SQL query and the following associated fields. Use this format:\n\ngenerated_query:[{\"sql_query\": \"Your SQL Query Here\", \"logic\": \"Explain briefly the logic you used\", \"response\": \"A friendly and conversational response to give more context to the user.\", \"chart\": {\"type\": \"The type of chart\", \"x_axis\": [\"Array of variables in the x-axis of the chart\"], \"y_axis\": [\"Array of variables in the y-axis of the chart\"]} }]\n\n## Database Schema:\n{\n \"order_values\": \"This table contains comprehensive order information including pricing, tax, discounts, returns, shipping, and product details. Each row represents a unique line item within an order and includes timestamps, statuses, and financials associated with the order.\",\n}\nCOLUMNS = {\n \"order_values\": {\n \"order_line_item_id\": {\n \"description\": \"Unique identifier for each line item in an order\",\n \"values_sample\": [\"shopify_5667598663969_14461737632033\"],\n },\n \"source\": {\n \"description\": \"Source of the order (e.g., platform or channel)\",\n \"values_sample\": [\"shopify\"],\n },\n \"order_id\": {\n \"description\": \"Unique identifier for each order\",\n \"values_sample\": [\"shopify_5667598663969\"],\n },\n \"ordered_quantity\": {\n \"description\": \"Quantity of each item ordered\",\n \"values_sample\": [1],\n },\n \"gross_sales_price_after_tax\": {\n \"description\": \"Gross sales price after tax is applied\",\n \"values_sample\": [150.00],\n },\n \"tax_percent\": {\n \"description\": \"Tax percentage applied to the order\",\n \"values_sample\": [18.0],\n },\n \"total_price_tax\": {\n \"description\": \"Total tax amount applied to the order\",\n \"values_sample\": [20.00],\n },\n \"gross_sales_price_before_tax\": {\n \"description\": \"Gross sales price before tax is applied\",\n \"values_sample\": [127.12],\n },\n \"total_discount_after_tax\": {\n \"description\": \"Total discount amount after tax is applied\",\n \"values_sample\": [10.00],\n },\n \"total_discount_tax\": {\n \"description\": \"Total tax amount on the discount applied\",\n \"values_sample\": [1.80],\n },\n \"total_discount_before_tax\": {\n \"description\": \"Total discount amount before tax is applied\",\n \"values_sample\": [8.20],\n },\n \"total_cancellation_returns_before_tax\": {\n \"description\": \"Total cancellation returns amount before tax\",\n \"values_sample\": [20.00],\n },\n \"total_rto_returns_before_tax\": {\n \"description\": \"Total RTO (Return to Origin) returns amount before tax\",\n \"values_sample\": [15.00],\n },\n \"total_returns_refund_before_tax\": {\n \"description\": \"Total refund amount before tax due to returns\",\n \"values_sample\": [30.00],\n },\n \"total_returns_before_tax\": {\n \"description\": \"Total returns amount before tax, including all types of returns\",\n \"values_sample\": [25.00],\n },\n \"total_return_tax\": {\n \"description\": \"Total tax amount on returns\",\n \"values_sample\": [4.50],\n },\n \"net_sales_before_tax\": {\n \"description\": \"Net sales amount before tax is applied\",\n \"values_sample\": [100.00],\n },\n \"item_shipping_charge\": {\n \"description\": \"Shipping charge for the item\",\n \"values_sample\": [5.00],\n },\n \"item_duties\": {\n \"description\": \"Duties charged for the item\",\n \"values_sample\": [3.00],\n },\n \"item_additional_fees\": {\n \"description\": \"Additional fees associated with the item\",\n \"values_sample\": [2.00],\n },\n \"total_tax\": {\n \"description\": \"Total tax amount applied to the order\",\n \"values_sample\": [18.00],\n },\n \"total_sales_after_tax\": {\n \"description\": \"Total sales amount after tax is applied\",\n \"values_sample\": [120.00],\n },\n \"gross_merchandise_value\": {\n \"description\": \"Gross merchandise value of the item\",\n \"values_sample\": [150.00],\n },\n \"sku_id\": {\n \"description\": \"Unique identifier for each SKU (Stock Keeping Unit)\",\n \"values_sample\": [\"shopify_8848983261473_47478863036705\"],\n },\n \"sku_code\": {\n \"description\": \"Code assigned to each SKU\",\n \"values_sample\": [\"BSL-D-SIP-0001\"],\n },\n \"product_category\": {\n \"description\": \"Category of the product\",\n \"values_sample\": [\"Insulated Sipper\"],\n },\n \"product_id\": {\n \"description\": \"Unique identifier for each product\",\n \"values_sample\": [\"shopify_8848983261473\"],\n },\n \"product_title\": {\n \"description\": \"Title of the product\",\n \"values_sample\": [\"Kids Sipper (430 ml)\"],\n },\n \"product_price\": {\n \"description\": \"Price of the product\",\n \"values_sample\": [999],\n },\n \"customer_id\": {\n \"description\": \"Unique identifier for each customer\",\n \"values_sample\": [\"shopify_7694075199777\"],\n },\n \"first_ordered_at\": {\n \"description\": \"Timestamp of the customer's first order\",\n \"values_sample\": [\"2024-02-14 16:00:13.000000\"],\n },\n \"order_refund_line_item_id\": {\n \"description\": \"Unique identifier for each refunded line item in an order\",\n \"values_sample\": [\"shopify_5667598663969_14461737632033\"],\n },\n \"order_date_time_utc\": {\n \"description\": \"Order date and time in UTC\",\n \"values_sample\": [\"2024-02-14 16:00:13.000000\"],\n },\n \"order_date_time\": {\n \"description\": \"Local date and time of the order\",\n \"values_sample\": [\"2024-02-14 11:00:13.000000\"],\n },\n \"order_date\": {\n \"description\": \"Date of the order\",\n \"values_sample\": [\"2024-02-14\"],\n },\n \"order_year\": {\n \"description\": \"Year of the order\",\n \"values_sample\": [2024],\n },\n \"order_quarter\": {\n \"description\": \"Quarter of the year when the order was placed\",\n \"values_sample\": [1],\n },\n \"order_month\": {\n \"description\": \"Month of the order\",\n \"values_sample\": [2],\n },\n \"order_day_of_month\": {\n \"description\": \"Day of the month of the order\",\n \"values_sample\": [14],\n },\n \"order_week\": {\n \"description\": \"Week of the year when the order was placed\",\n \"values_sample\": [7],\n },\n \"order_day_of_week\": {\n \"description\": \"Day of the week of the order\",\n \"values_sample\": [4], # Assuming Sunday is 0\n },\n \"order_hour\": {\n \"description\": \"Hour of the day when the order was placed\",\n \"values_sample\": [16],\n },\n \"order_minute\": {\n \"description\": \"Minute of the hour when the order was placed\",\n \"values_sample\": [0],\n },\n \"order_time\": {\n \"description\": \"Time of the order\",\n \"values_sample\": [\"16:00\"],\n },\n \"refund_status\": {\n \"description\": \"Refund status of the order\",\n \"values_sample\": [\"false\"],\n },\n \"rto_status\": {\n \"description\": \"Return to Origin (RTO) status of the order\",\n \"values_sample\": [\"false\"],\n },\n \"cancellation_status\": {\n \"description\": \"Cancellation status of the order\",\n \"values_sample\": [\"false\"],\n },\n \"order_status\": {\n \"description\": \"Current status of the order\",\n \"values_sample\": [\"completed\"],\n },\n \"payment_status\": {\n \"description\": \"Payment status of the order\",\n \"values_sample\": [\"paid\"],\n },\n \"return_reason\": {\n \"description\": \"Reason for return, if applicable\",\n \"values_sample\": [\"damaged item\"],\n },\n \"billing_address_city\": {\n \"description\": \"City of the billing address\",\n \"values_sample\": [\"Surat\"],\n },\n \"billing_address_state\": {\n \"description\": \"State of the billing address\",\n \"values_sample\": [\"Gujarat\"],\n },\n \"billing_address_country\": {\n \"description\": \"Country of the billing address\",\n \"values_sample\": [\"India\"],\n },\n \"gift_wrap_expense\": {\n \"description\": \"Expense incurred for gift wrapping\",\n \"values_sample\": [5.00],\n },\n \"packaging_expense\": {\n \"description\": \"Expense incurred for packaging\",\n \"values_sample\": [3.00],\n },\n \"handling_expense\": {\n \"description\": \"Expense incurred for handling\",\n \"values_sample\": [2.00],\n },\n \"shipping_expense\": {\n \"description\": \"Expense incurred for shipping\",\n \"values_sample\": [10.00],\n },\n \"marketplace_expense\": {\n \"description\": \"Marketplace fees associated with the order\",\n \"values_sample\": [8.00],\n },\n \"payment_gateway_expense\": {\n \"description\": \"Fees charged by the payment gateway\",\n \"values_sample\": [4.00],\n },\n \"other_adjustments\": {\n \"description\": \"Other adjustments related to the order\",\n \"values_sample\": [2.50],\n },\n \"estimated_expense\": {\n \"description\": \"Estimated total expense for the order\",\n \"values_sample\": [20.00],\n },\n \"sku_cost\": {\n \"description\": \"Cost of the SKU\",\n \"values_sample\": [75.00],\n },\n \"gross_profit\": {\n \"description\": \"Gross profit for the order\",\n \"values_sample\": [50.00],\n },\n \"cm1_expense\": {\n \"description\": \"CM1 (Contribution Margin 1) expense\",\n \"values_sample\": [10.00],\n },\n \"profit_cm1\": {\n \"description\": \"CM1 profit for the order\",\n \"values_sample\": [40.00],\n },\n \"_synced_at\": {\n \"description\": \"Timestamp when the data was last synced\",\n \"values_sample\": [\"2024-02-14 16:30:00.000000\"],\n },\n },\n}\n\n## Guidelines that are necessary to follow for making correct SQL queries:\n1. Whenever working with any text fields, always cast both column and value to lowercase before performing any operations on them.\n2. Chart Type, X-axis and Y-axis will be \"null\" when the question asks for a single value instead of a trend or split.\n3. Ensure numeric typecasting for numerators in division operations.\n4. Use lowercase for string matching to maintain consistency. Note: Do type casting to varchar only if needed (mainly in case of Mssql DB type).\n5. Apply the same operation in both GROUP BY and SELECT clauses when referencing the same field.\n6. Create aliases for fields in SELECT on which operations are applied.\n7. Always prefix field names with table or alias names in joins.\n8. Treat numeric fields as measures and text, enums, and time fields as dimensions in aggregation queries.\n9. Please do not refer the database name in column or table names.\n10. Prevent zero division errors by validating the denominator in division operations.\n11. Exclude null values in aggregations of numeric fields.\n12. Use LOWER in GROUP BY only if the same column in SELECT is also in LOWER.\n13. Please consider the granularity level of the table and do appropriate aggregations.\ne.g.: If order_data table has Order ID - SKU ID columns, and question is asked at order level, group rows by Order ID. Write queries accordingly.\n14. In case time period is not mentioned, use last 12 calendar months data only for calculations, unless lifetime value like questions are asked.\n15. Consider order by ABS value wherever seems logical.\n16. Round the calculations to 2 decimal points at appropriate places, like AVG and Percentages.\n17. Please type-cast the date columns appropriately before making any date based comparisons (only if needed). E.g. for IBM I DB2 ``` to_date(cast(date_column as char(8)),'YYYYMMDD') < current date' ```\n\n## Additional guidelines specific for IBM I DB2:\n18. In case of IBM I DB2 queries do not end with semi-colon ';'\n19. In case of IBM I DB2 syntax to get top x rows is 'FETCH TOP x ROWS ONLY'.\n20. Column names in IBM I DB2 are in upper case and should match in chart dict.\n\n## Response:\n","role":"system"},{"content":"How many repeat purchases were made in Q1 2024?","role":"user"},{"content":"SELECT SUM(CASE WHEN order_count > 1 THEN order_count - 1 ELSE 0 END) AS repeat_purchases FROM ( SELECT customer_id, COUNT(DISTINCT order_id) AS order_count FROM order_values WHERE order_year = 2024 AND order_quarter = 1 GROUP BY customer_id ) AS subquery;","role":"assistant"}]} {"question":"Split of average order value AOV by new and returning customers","ground_truth_query":"WITH first_orders AS ( SELECT customer_id, MIN(CAST(first_ordered_at AS DATE)) AS first_order_date FROM order_values GROUP BY customer_id), order_totals AS ( SELECT order_id, customer_id, SUM(net_sales_before_tax) AS total_net_sales_before_tax FROM order_values WHERE refund_status = 'false' AND cancellation_status = 'false' AND order_date < DATE_TRUNC('month', CURRENT_DATE) AND order_date >= DATE_TRUNC('month', ADD_MONTHS(CURRENT_DATE, -12)) GROUP BY order_id, customer_id) SELECT CASE WHEN f.first_order_date = o.order_date THEN 'new' ELSE 'returning' END AS customer_type, ROUND(AVG(ot.total_net_sales_before_tax), 2) AS avg_order_value FROM order_totals ot JOIN order_values o ON ot.order_id = o.order_id JOIN first_orders f ON o.customer_id = f.customer_id GROUP BY CASE WHEN f.first_order_date = o.order_date THEN 'new' ELSE 'returning' END;","execution_status_gtu":"Success","execution_result_gtu":" customer_type avg_order_value\n0 new 779.54\n1 returning 840.32","llama_sqlcoder_3_few_promp":"SELECT o.order_id, o.source, o.customer_id, AVG(o.net_sales_before_tax) AS average_order_value, CASE WHEN o.first_ordered_at::DATE <= (CURRENT_DATE - INTERVAL '3 months') THEN'returning' ELSE 'new' END AS customer_type FROM order_values o WHERE o.order_date >= (CURRENT_DATE - INTERVAL '1 year') GROUP BY o.order_id, o.source, o.customer_id, CASE WHEN o.first_ordered_at::DATE <= (CURRENT_DATE - INTERVAL '3 months') THEN'returning' ELSE 'new' END ORDER BY o.order_id, o.source, o.customer_id, customer_type NULLS LAST;","execution_status_llama":"Success","execution_result_llama":null,"messages":[{"content":"\nYou are a SQL expert in Mysql. As a SQL expert, your job is to answer data related questions from the business team accurately by writing SQL queries. Refer to the provided database schema for tables and columns. Do not correct spelling mistakes in the schema.\n\nPlease generate only read\/SELECT queries for data safety. If a question cannot be answered using a SELECT operation, it should not be addressed.\nRefer the sample queries to see how date filters and calculations are done. Pay high attention on sample queries that seem most relevant to user question.\n\nFormat your responses as JSON, including the SQL query and the following associated fields. Use this format:\n\ngenerated_query:[{\"sql_query\": \"Your SQL Query Here\", \"logic\": \"Explain briefly the logic you used\", \"response\": \"A friendly and conversational response to give more context to the user.\", \"chart\": {\"type\": \"The type of chart\", \"x_axis\": [\"Array of variables in the x-axis of the chart\"], \"y_axis\": [\"Array of variables in the y-axis of the chart\"]} }]\n\n## Database Schema:\n{\n \"order_values\": \"This table contains comprehensive order information including pricing, tax, discounts, returns, shipping, and product details. Each row represents a unique line item within an order and includes timestamps, statuses, and financials associated with the order.\",\n}\nCOLUMNS = {\n \"order_values\": {\n \"order_line_item_id\": {\n \"description\": \"Unique identifier for each line item in an order\",\n \"values_sample\": [\"shopify_5667598663969_14461737632033\"],\n },\n \"source\": {\n \"description\": \"Source of the order (e.g., platform or channel)\",\n \"values_sample\": [\"shopify\"],\n },\n \"order_id\": {\n \"description\": \"Unique identifier for each order\",\n \"values_sample\": [\"shopify_5667598663969\"],\n },\n \"ordered_quantity\": {\n \"description\": \"Quantity of each item ordered\",\n \"values_sample\": [1],\n },\n \"gross_sales_price_after_tax\": {\n \"description\": \"Gross sales price after tax is applied\",\n \"values_sample\": [150.00],\n },\n \"tax_percent\": {\n \"description\": \"Tax percentage applied to the order\",\n \"values_sample\": [18.0],\n },\n \"total_price_tax\": {\n \"description\": \"Total tax amount applied to the order\",\n \"values_sample\": [20.00],\n },\n \"gross_sales_price_before_tax\": {\n \"description\": \"Gross sales price before tax is applied\",\n \"values_sample\": [127.12],\n },\n \"total_discount_after_tax\": {\n \"description\": \"Total discount amount after tax is applied\",\n \"values_sample\": [10.00],\n },\n \"total_discount_tax\": {\n \"description\": \"Total tax amount on the discount applied\",\n \"values_sample\": [1.80],\n },\n \"total_discount_before_tax\": {\n \"description\": \"Total discount amount before tax is applied\",\n \"values_sample\": [8.20],\n },\n \"total_cancellation_returns_before_tax\": {\n \"description\": \"Total cancellation returns amount before tax\",\n \"values_sample\": [20.00],\n },\n \"total_rto_returns_before_tax\": {\n \"description\": \"Total RTO (Return to Origin) returns amount before tax\",\n \"values_sample\": [15.00],\n },\n \"total_returns_refund_before_tax\": {\n \"description\": \"Total refund amount before tax due to returns\",\n \"values_sample\": [30.00],\n },\n \"total_returns_before_tax\": {\n \"description\": \"Total returns amount before tax, including all types of returns\",\n \"values_sample\": [25.00],\n },\n \"total_return_tax\": {\n \"description\": \"Total tax amount on returns\",\n \"values_sample\": [4.50],\n },\n \"net_sales_before_tax\": {\n \"description\": \"Net sales amount before tax is applied\",\n \"values_sample\": [100.00],\n },\n \"item_shipping_charge\": {\n \"description\": \"Shipping charge for the item\",\n \"values_sample\": [5.00],\n },\n \"item_duties\": {\n \"description\": \"Duties charged for the item\",\n \"values_sample\": [3.00],\n },\n \"item_additional_fees\": {\n \"description\": \"Additional fees associated with the item\",\n \"values_sample\": [2.00],\n },\n \"total_tax\": {\n \"description\": \"Total tax amount applied to the order\",\n \"values_sample\": [18.00],\n },\n \"total_sales_after_tax\": {\n \"description\": \"Total sales amount after tax is applied\",\n \"values_sample\": [120.00],\n },\n \"gross_merchandise_value\": {\n \"description\": \"Gross merchandise value of the item\",\n \"values_sample\": [150.00],\n },\n \"sku_id\": {\n \"description\": \"Unique identifier for each SKU (Stock Keeping Unit)\",\n \"values_sample\": [\"shopify_8848983261473_47478863036705\"],\n },\n \"sku_code\": {\n \"description\": \"Code assigned to each SKU\",\n \"values_sample\": [\"BSL-D-SIP-0001\"],\n },\n \"product_category\": {\n \"description\": \"Category of the product\",\n \"values_sample\": [\"Insulated Sipper\"],\n },\n \"product_id\": {\n \"description\": \"Unique identifier for each product\",\n \"values_sample\": [\"shopify_8848983261473\"],\n },\n \"product_title\": {\n \"description\": \"Title of the product\",\n \"values_sample\": [\"Kids Sipper (430 ml)\"],\n },\n \"product_price\": {\n \"description\": \"Price of the product\",\n \"values_sample\": [999],\n },\n \"customer_id\": {\n \"description\": \"Unique identifier for each customer\",\n \"values_sample\": [\"shopify_7694075199777\"],\n },\n \"first_ordered_at\": {\n \"description\": \"Timestamp of the customer's first order\",\n \"values_sample\": [\"2024-02-14 16:00:13.000000\"],\n },\n \"order_refund_line_item_id\": {\n \"description\": \"Unique identifier for each refunded line item in an order\",\n \"values_sample\": [\"shopify_5667598663969_14461737632033\"],\n },\n \"order_date_time_utc\": {\n \"description\": \"Order date and time in UTC\",\n \"values_sample\": [\"2024-02-14 16:00:13.000000\"],\n },\n \"order_date_time\": {\n \"description\": \"Local date and time of the order\",\n \"values_sample\": [\"2024-02-14 11:00:13.000000\"],\n },\n \"order_date\": {\n \"description\": \"Date of the order\",\n \"values_sample\": [\"2024-02-14\"],\n },\n \"order_year\": {\n \"description\": \"Year of the order\",\n \"values_sample\": [2024],\n },\n \"order_quarter\": {\n \"description\": \"Quarter of the year when the order was placed\",\n \"values_sample\": [1],\n },\n \"order_month\": {\n \"description\": \"Month of the order\",\n \"values_sample\": [2],\n },\n \"order_day_of_month\": {\n \"description\": \"Day of the month of the order\",\n \"values_sample\": [14],\n },\n \"order_week\": {\n \"description\": \"Week of the year when the order was placed\",\n \"values_sample\": [7],\n },\n \"order_day_of_week\": {\n \"description\": \"Day of the week of the order\",\n \"values_sample\": [4], # Assuming Sunday is 0\n },\n \"order_hour\": {\n \"description\": \"Hour of the day when the order was placed\",\n \"values_sample\": [16],\n },\n \"order_minute\": {\n \"description\": \"Minute of the hour when the order was placed\",\n \"values_sample\": [0],\n },\n \"order_time\": {\n \"description\": \"Time of the order\",\n \"values_sample\": [\"16:00\"],\n },\n \"refund_status\": {\n \"description\": \"Refund status of the order\",\n \"values_sample\": [\"false\"],\n },\n \"rto_status\": {\n \"description\": \"Return to Origin (RTO) status of the order\",\n \"values_sample\": [\"false\"],\n },\n \"cancellation_status\": {\n \"description\": \"Cancellation status of the order\",\n \"values_sample\": [\"false\"],\n },\n \"order_status\": {\n \"description\": \"Current status of the order\",\n \"values_sample\": [\"completed\"],\n },\n \"payment_status\": {\n \"description\": \"Payment status of the order\",\n \"values_sample\": [\"paid\"],\n },\n \"return_reason\": {\n \"description\": \"Reason for return, if applicable\",\n \"values_sample\": [\"damaged item\"],\n },\n \"billing_address_city\": {\n \"description\": \"City of the billing address\",\n \"values_sample\": [\"Surat\"],\n },\n \"billing_address_state\": {\n \"description\": \"State of the billing address\",\n \"values_sample\": [\"Gujarat\"],\n },\n \"billing_address_country\": {\n \"description\": \"Country of the billing address\",\n \"values_sample\": [\"India\"],\n },\n \"gift_wrap_expense\": {\n \"description\": \"Expense incurred for gift wrapping\",\n \"values_sample\": [5.00],\n },\n \"packaging_expense\": {\n \"description\": \"Expense incurred for packaging\",\n \"values_sample\": [3.00],\n },\n \"handling_expense\": {\n \"description\": \"Expense incurred for handling\",\n \"values_sample\": [2.00],\n },\n \"shipping_expense\": {\n \"description\": \"Expense incurred for shipping\",\n \"values_sample\": [10.00],\n },\n \"marketplace_expense\": {\n \"description\": \"Marketplace fees associated with the order\",\n \"values_sample\": [8.00],\n },\n \"payment_gateway_expense\": {\n \"description\": \"Fees charged by the payment gateway\",\n \"values_sample\": [4.00],\n },\n \"other_adjustments\": {\n \"description\": \"Other adjustments related to the order\",\n \"values_sample\": [2.50],\n },\n \"estimated_expense\": {\n \"description\": \"Estimated total expense for the order\",\n \"values_sample\": [20.00],\n },\n \"sku_cost\": {\n \"description\": \"Cost of the SKU\",\n \"values_sample\": [75.00],\n },\n \"gross_profit\": {\n \"description\": \"Gross profit for the order\",\n \"values_sample\": [50.00],\n },\n \"cm1_expense\": {\n \"description\": \"CM1 (Contribution Margin 1) expense\",\n \"values_sample\": [10.00],\n },\n \"profit_cm1\": {\n \"description\": \"CM1 profit for the order\",\n \"values_sample\": [40.00],\n },\n \"_synced_at\": {\n \"description\": \"Timestamp when the data was last synced\",\n \"values_sample\": [\"2024-02-14 16:30:00.000000\"],\n },\n },\n}\n\n## Guidelines that are necessary to follow for making correct SQL queries:\n1. Whenever working with any text fields, always cast both column and value to lowercase before performing any operations on them.\n2. Chart Type, X-axis and Y-axis will be \"null\" when the question asks for a single value instead of a trend or split.\n3. Ensure numeric typecasting for numerators in division operations.\n4. Use lowercase for string matching to maintain consistency. Note: Do type casting to varchar only if needed (mainly in case of Mssql DB type).\n5. Apply the same operation in both GROUP BY and SELECT clauses when referencing the same field.\n6. Create aliases for fields in SELECT on which operations are applied.\n7. Always prefix field names with table or alias names in joins.\n8. Treat numeric fields as measures and text, enums, and time fields as dimensions in aggregation queries.\n9. Please do not refer the database name in column or table names.\n10. Prevent zero division errors by validating the denominator in division operations.\n11. Exclude null values in aggregations of numeric fields.\n12. Use LOWER in GROUP BY only if the same column in SELECT is also in LOWER.\n13. Please consider the granularity level of the table and do appropriate aggregations.\ne.g.: If order_data table has Order ID - SKU ID columns, and question is asked at order level, group rows by Order ID. Write queries accordingly.\n14. In case time period is not mentioned, use last 12 calendar months data only for calculations, unless lifetime value like questions are asked.\n15. Consider order by ABS value wherever seems logical.\n16. Round the calculations to 2 decimal points at appropriate places, like AVG and Percentages.\n17. Please type-cast the date columns appropriately before making any date based comparisons (only if needed). E.g. for IBM I DB2 ``` to_date(cast(date_column as char(8)),'YYYYMMDD') < current date' ```\n\n## Additional guidelines specific for IBM I DB2:\n18. In case of IBM I DB2 queries do not end with semi-colon ';'\n19. In case of IBM I DB2 syntax to get top x rows is 'FETCH TOP x ROWS ONLY'.\n20. Column names in IBM I DB2 are in upper case and should match in chart dict.\n\n## Response:\n","role":"system"},{"content":"Split of average order value AOV by new and returning customers","role":"user"},{"content":"WITH first_orders AS ( SELECT customer_id, MIN(CAST(first_ordered_at AS DATE)) AS first_order_date FROM order_values GROUP BY customer_id), order_totals AS ( SELECT order_id, customer_id, SUM(net_sales_before_tax) AS total_net_sales_before_tax FROM order_values WHERE refund_status = 'false' AND cancellation_status = 'false' AND order_date < DATE_TRUNC('month', CURRENT_DATE) AND order_date >= DATE_TRUNC('month', ADD_MONTHS(CURRENT_DATE, -12)) GROUP BY order_id, customer_id) SELECT CASE WHEN f.first_order_date = o.order_date THEN 'new' ELSE 'returning' END AS customer_type, ROUND(AVG(ot.total_net_sales_before_tax), 2) AS avg_order_value FROM order_totals ot JOIN order_values o ON ot.order_id = o.order_id JOIN first_orders f ON o.customer_id = f.customer_id GROUP BY CASE WHEN f.first_order_date = o.order_date THEN 'new' ELSE 'returning' END;","role":"assistant"}]}