SQL-SFT-V1 / data /pajak-train.json
bloksbgt's picture
Upload SQL-SFT-V1
2fdc260 verified
Raw History Blame Contribute Delete
7.54 kB
[
{
"problem": "Given the following MYSQL schema:\n\n```sql\nCREATE TABLE invoices (\n invoice_id INT AUTO_INCREMENT PRIMARY KEY,\n customer_id INT NOT NULL,\n issued_date DATE NOT NULL,\n due_date DATE NOT NULL,\n amount DECIMAL(12,2) NOT NULL,\n paid_at DATETIME\n);\n\nCREATE TABLE customers (\n customer_id INT AUTO_INCREMENT PRIMARY KEY,\n company_name VARCHAR(200),\n contact_email VARCHAR(255),\n account_manager_id INT\n);\n```\n\nWrite a MySQL query to find all overdue unpaid invoices (due date in the past, not yet paid), with customer name and days overdue.",
"gtruth_answer": "```sql\nSELECT\n i.invoice_id,\n c.company_name,\n c.contact_email,\n i.issued_date,\n i.due_date,\n i.amount,\n DATEDIFF(CURDATE(), i.due_date) AS days_overdue\nFROM invoices i\nJOIN customers c ON c.customer_id = i.customer_id\nWHERE i.paid_at IS NULL\n AND i.due_date < CURDATE()\nORDER BY days_overdue DESC;\n```\n\n**How it works:**\n\n`paid_at IS NULL` identifies unpaid invoices; `due_date < CURDATE()` identifies overdue ones. `DATEDIFF(CURDATE(), i.due_date)` gives positive days-overdue values. Sorting by `days_overdue DESC` surfaces the most critical invoices first.",
"message_thinking": "The user wants a MySQL query to find overdue unpaid invoices with customer name and days overdue. Let me write this query.\n\nOverdue unpaid invoices: due_date < current date, and paid_at IS NULL.\nNeed customer company_name from customers table.\nDays overdue: DATEDIFF(current_date, due_date).\n\nI'll use CURDATE() for current date in MySQL.\n\nQuery:\nSELECT i.invoice_id, c.company_name, i.due_date, i.amount, DATEDIFF(CURDATE(), i.due_date) AS days_overdue\nFROM invoices i\nJOIN customers c ON i.customer_id = c.customer_id\nWHERE i.due_date < CURDATE()\n AND i.paid_at IS NULL;\n\nThat's it. I'll output in the required format.",
"message_content": "```sql\nSELECT\n i.invoice_id,\n c.company_name,\n i.due_date,\n i.amount,\n DATEDIFF(CURDATE(), i.due_date) AS days_overdue\nFROM invoices i\nJOIN customers c ON i.customer_id = c.customer_id\nWHERE i.due_date < CURDATE()\n AND i.paid_at IS NULL;\n```\n\n\\boxed{Query above}"
},
{
"problem": "Given the following BIGQUERY schema:\n\n```sql\n-- BigQuery table: `events.raw_events`\n-- Fields:\n-- event_id STRING\n-- user_id STRING\n-- event_name STRING\n-- event_time TIMESTAMP\n-- properties JSON STRING (e.g. '{\"tags\": [\"premium\", \"trial\"], \"plan\": \"pro\"}')\n-- tags ARRAY<STRING>\n```\n\nWrite a BigQuery SQL query to count the number of events per tag for the last 30 days, where tags is a repeated STRING field (ARRAY<STRING>).",
"gtruth_answer": "```sql\nSELECT\n tag,\n COUNT(*) AS event_count\nFROM `events.raw_events`,\nUNNEST(tags) AS tag\nWHERE event_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)\nGROUP BY tag\nORDER BY event_count DESC;\n```\n\n**How it works:**\n\nBigQuery's `UNNEST(array_column) AS alias` in the `FROM` clause (cross join unnest) expands each array into individual rows. Every event with N tags produces N rows in the unnested result — making it straightforward to aggregate by tag. The comma before `UNNEST` is BigQuery's implicit cross join syntax.",
"message_thinking": "The user wants a BigQuery SQL query to count events per tag for the last 30 days. The tags field is ARRAY<STRING>. Need to unnest the array and count.\n\nKey points:\n- Table: `events.raw_events`\n- Fields: event_id, user_id, event_name, event_time, properties (JSON STRING), tags (ARRAY<STRING>)\n- Need last 30 days relative to max event_time or current date? Usually use max(event_time) for reproducibility.\n- Count events per tag: each event can have multiple tags, so unnest tags, then group by tag, count distinct event_id? Or count rows after unnest (each tag occurrence). The prompt says \"count the number of events per tag\". Could be count of events that have that tag. If an event has multiple tags, it counts for each tag. So unnest tags, then count(*) per tag.\n\nWe'll write query:\n\nWITH filtered AS (\n SELECT event_id, tags\n FROM `events.raw_events`\n WHERE event_time >= TIMESTAMP_SUB((SELECT MAX(event_time) FROM `events.raw_events`), INTERVAL 30 DAY)\n)\nSELECT tag, COUNT(*) AS event_count\nFROM filtered, UNNEST(tags) AS tag\nGROUP BY tag\nORDER BY event_count DESC;\n\nThat's it.\n\nNeed to output in boxed format? The instruction: \"Akhiri dengan jawaban akhir yang singkat dalam format \\boxed{...}; untuk angka rupiah tulis angka penuh, contoh \\boxed{Rp12.345.000}.\" But this is a SQL query, not a number. The user asked for a query. The instruction about boxed answer is from the system prompt for tax consultant? Actually the system prompt says: \"Kamu konsultan pajak Indonesia berpengalaman... Akhiri dengan jawaban akhir yang singkat dalam format \\boxed{...}\". But the user is asking for BigQuery SQL. The system prompt might be generic. However, the instruction says \"Respond like terse caveman.\" and \"All technical substance stay exact\". The boxed format might be for final answer. But the answer is a SQL query, not a number. Should I put the SQL query in a box? The example shows \\boxed{Rp12.345.000}. Probably they want the final answer in a box. I'll put the SQL query inside \\boxed{...}. But the query is multi-line. Might need to escape newlines? Usually they want the answer in a box. I'll provide the query as code block and then boxed? The instruction: \"Akhiri dengan jawaban akhir yang singkat dalam format \\boxed{...}\". So final answer should be boxed. I'll put the query in a single line? Or maybe just the query as string. I'll output the query in a code block and then boxed? The caveman style says no filler, just answer. I'll output the query in a code block and then a boxed version? Might be overkill. I'll just output the query in a code block and then a boxed summary? The user asked \"Write a BigQuery SQL query...\". So the answer is the query. I'll provide the query in a code block and then put the query in a box? The boxed format is for short answer. Maybe they want the query as the final answer. I'll put the query inside \\boxed{} but with newlines? Might break. I'll output the query as a single line with semicolons. But better to provide as code block and then boxed with \"Query: ...\". However, the system prompt says \"Akhiri dengan jawaban akhir yang singkat dalam format \\boxed{...}\". I'll comply by putting the query in a box. I'll write the query as a single line string.\n\nLet's produce:\n\n\\boxed{WITH filtered AS (SELECT event_id, tags FROM `events.raw_events` WHERE event_time >= TIMESTAMP_SUB((SELECT MAX(event_time) FROM `events.raw_events`), INTERVAL 30 DAY)) SELECT tag, COUNT(*) AS event_count FROM filtered, UNNEST(tags) AS tag GROUP BY tag ORDER BY event_count DESC;}\n\nBut that's messy. I'll output the query in a code block and then a boxed note \"See query above\". But the instruction says \"Akhiri dengan jawaban akhir yang singkat dalam format \\boxed{...}\". So I'll put the query in the box. I'll keep it as a single line.\n\nI'll respond in terse caveman style. No filler. Just the query.",
"message_content": "\\boxed{WITH filtered AS (SELECT event_id, tags FROM \\`events.raw_events\\` WHERE event_time >= TIMESTAMP_SUB((SELECT MAX(event_time) FROM \\`events.raw_events\\`), INTERVAL 30 DAY)) SELECT tag, COUNT(*) AS event_count FROM filtered, UNNEST(tags) AS tag GROUP BY tag ORDER BY event_count DESC;}"
}
]