请求 #1
SEQ 109{
"isolation_policy_hash": "7c962b44b76369de5a795edbc2504a619f4ac15b62eba4dd5b88e714081115b0",
"status": "running"
}案例记录 case-run-00159
将 2026 年已完成订单按金额分层:total_amount 大于等于 2000 为 high,大于等于 1000 且小于 2000 为 medium,其余为 low;输出 order_id、total_amount、amount_band,并按 total_amount 降序、order_id 升序;必须使用 CASE。
以下字段来自本次运行的冻结记录。
#18#1591completed19,855不可估算未记录189mscodex_clitextgpt-5.6-solgpt-5.6-sol未提供2026年8月29日 22:522026年8月29日 22:525b5d98876ea35114f18ce6dfa48cc9800d88b6baba80d311b2f52552a38b31af显示本次实际保存的完整 Prompt。
你是 Text-to-SQL 数据分析与数据开发生成器。先形成简洁、可审计的结构化查询方案,再生成完成问题所需的 SQL;不要输出隐藏推理。
方言与安全规则:
Use DuckDB SQL. Return exactly one read-only query. Do not access files, URLs, extensions, or schemas outside the supplied tables.
数据库结构:
{"semantic_relationships":[{"cardinality":"many_to_one","from_entity":"order","sql_on":"fact_orders.customer_id = dim_customers.customer_id","to_entity":"customer"},{"cardinality":"many_to_one","from_entity":"order","sql_on":"fact_orders.channel_id = dim_channels.channel_id","to_entity":"channel"},{"cardinality":"many_to_one","from_entity":"order_item","sql_on":"fact_order_items.order_id = fact_orders.order_id","to_entity":"order"},{"cardinality":"many_to_one","from_entity":"order_item","sql_on":"fact_order_items.product_id = dim_products.product_id","to_entity":"product"},{"cardinality":"many_to_one","from_entity":"payment","sql_on":"fact_payments.order_id = fact_orders.order_id","to_entity":"order"},{"cardinality":"many_to_one","from_entity":"return","sql_on":"fact_returns.order_id = fact_order_items.order_id AND fact_returns.line_no = fact_order_items.line_no","to_entity":"order_item"}],"tables":[{"columns":[{"data_type":"BIGINT","name":"channel_id","nullable":false},{"data_type":"VARCHAR","name":"channel_name","nullable":false},{"data_type":"VARCHAR","name":"channel_type","nullable":false}],"foreign_keys":[],"name":"dim_channels","primary_key":["channel_id"]},{"columns":[{"data_type":"BIGINT","name":"customer_id","nullable":false},{"data_type":"VARCHAR","name":"customer_name","nullable":false},{"data_type":"VARCHAR","name":"city","nullable":true},{"data_type":"DATE","name":"signup_date","nullable":false},{"data_type":"VARCHAR","name":"segment","nullable":false}],"foreign_keys":[],"name":"dim_customers","primary_key":["customer_id"]},{"columns":[{"data_type":"BIGINT","name":"product_id","nullable":false},{"data_type":"VARCHAR","name":"product_name","nullable":false},{"data_type":"VARCHAR","name":"category","nullable":false},{"data_type":"VARCHAR","name":"brand","nullable":false},{"data_type":"DECIMAL(14,2)","name":"list_price","nullable":false}],"foreign_keys":[],"name":"dim_products","primary_key":["product_id"]},{"columns":[{"data_type":"BIGINT","name":"order_id","nullable":false},{"data_type":"BIGINT","name":"line_no","nullable":false},{"data_type":"BIGINT","name":"product_id","nullable":false},{"data_type":"BIGINT","name":"quantity","nullable":false},{"data_type":"DECIMAL(14,2)","name":"unit_price","nullable":false},{"data_type":"DECIMAL(14,2)","name":"discount_amount","nullable":false}],"foreign_keys":[{"columns":["order_id"],"referenced_columns":["order_id"],"referenced_table":"fact_orders"},{"columns":["product_id"],"referenced_columns":["product_id"],"referenced_table":"dim_products"}],"name":"fact_order_items","primary_key":["order_id","line_no"]},{"columns":[{"data_type":"BIGINT","name":"order_id","nullable":false},{"data_type":"BIGINT","name":"customer_id","nullable":false},{"data_type":"BIGINT","name":"channel_id","nullable":false},{"data_type":"DATE","name":"order_date","nullable":false},{"data_type":"VARCHAR","name":"status","nullable":false},{"data_type":"DECIMAL(14,2)","name":"total_amount","nullable":false}],"foreign_keys":[{"columns":["customer_id"],"referenced_columns":["customer_id"],"referenced_table":"dim_customers"},{"columns":["channel_id"],"referenced_columns":["channel_id"],"referenced_table":"dim_channels"}],"name":"fact_orders","primary_key":["order_id"]},{"columns":[{"data_type":"BIGINT","name":"payment_id","nullable":false},{"data_type":"BIGINT","name":"order_id","nullable":false},{"data_type":"TIMESTAMP","name":"paid_at","nullable":false},{"data_type":"VARCHAR","name":"payment_method","nullable":false},{"data_type":"DECIMAL(14,2)","name":"amount","nullable":false},{"data_type":"VARCHAR","name":"status","nullable":false}],"foreign_keys":[{"columns":["order_id"],"referenced_columns":["order_id"],"referenced_table":"fact_orders"}],"name":"fact_payments","primary_key":["payment_id"]},{"columns":[{"data_type":"BIGINT","name":"return_id","nullable":false},{"data_type":"BIGINT","name":"order_id","nullable":false},{"data_type":"BIGINT","name":"line_no","nullable":false},{"data_type":"TIMESTAMP","name":"returned_at","nullable":false},{"data_type":"BIGINT","name":"return_qty","nullable":false},{"data_type":"DECIMAL(14,2)","name":"refund_amount","nullable":false},{"data_type":"VARCHAR","name":"reason","nullable":true}],"foreign_keys":[{"columns":["order_id","line_no"],"referenced_columns":["order_id","line_no"],"referenced_table":"fact_order_items"}],"name":"fact_returns","primary_key":["return_id"]}]}
语义层与业务口径:
{"business_rules":["完成订单仅指 fact_orders.status = 'completed'。","净销售额为 quantity * unit_price - discount_amount。","paid、refunded、failed 金额只按 fact_payments.status 分类。","退货率为完成订单的 returned_qty / sold_qty,售出数量仅含完成订单。","月份按 UTC Gregorian calendar 计算。","订单头 total_amount 应等于订单行净额汇总,差异视为数据质量异常。"],"dimensions":[{"data_type":"VARCHAR","description":"客户分群","expression":"dim_customers.segment","name":"customer_segment"},{"data_type":"VARCHAR","description":"商品品类","expression":"dim_products.category","name":"product_category"},{"data_type":"VARCHAR","description":"渠道类型","expression":"dim_channels.channel_type","name":"channel_type"},{"data_type":"VARCHAR","description":"UTC Gregorian 月份","expression":"strftime(fact_orders.order_date, '%Y-%m')","name":"order_month"}],"entities":[{"description":"客户主数据","grain":"每行一个客户","name":"customer","primary_key":["customer_id"],"table":"dim_customers"},{"description":"商品主数据","grain":"每行一个商品","name":"product","primary_key":["product_id"],"table":"dim_products"},{"description":"渠道主数据","grain":"每行一个渠道","name":"channel","primary_key":["channel_id"],"table":"dim_channels"},{"description":"订单头","grain":"每行一个订单","name":"order","primary_key":["order_id"],"table":"fact_orders"},{"description":"订单行","grain":"每行一个订单商品行","name":"order_item","primary_key":["order_id","line_no"],"table":"fact_order_items"},{"description":"支付尝试","grain":"每行一笔支付","name":"payment","primary_key":["payment_id"],"table":"fact_payments"},{"description":"退货记录","grain":"每行一条订单行退货","name":"return","primary_key":["return_id"],"table":"fact_returns"}],"metrics":[{"description":"已完成订单数","expression":"COUNT(DISTINCT CASE WHEN fact_orders.status = 'completed' THEN fact_orders.order_id END)","filters":["fact_orders.status = 'completed'"],"grain":"聚合","name":"completed_order_count"},{"description":"完成订单商品行净销售额","expression":"SUM(fact_order_items.quantity * fact_order_items.unit_price - fact_order_items.discount_amount)","filters":["fact_orders.status = 'completed'"],"grain":"聚合","name":"net_revenue"},{"description":"成功支付金额","expression":"SUM(CASE WHEN fact_payments.status = 'paid' THEN fact_payments.amount ELSE 0 END)","filters":[],"grain":"聚合","name":"paid_amount"},{"description":"退款状态支付金额","expression":"SUM(CASE WHEN fact_payments.status = 'refunded' THEN fact_payments.amount ELSE 0 END)","filters":[],"grain":"聚合","name":"refunded_amount"},{"description":"失败支付金额","expression":"SUM(CASE WHEN fact_payments.status = 'failed' THEN fact_payments.amount ELSE 0 END)","filters":[],"grain":"聚合","name":"failed_amount"},{"description":"完成订单退货数量除以售出数量","expression":"SUM(fact_returns.return_qty) / SUM(fact_order_items.quantity)","filters":["fact_orders.status = 'completed'"],"grain":"聚合","name":"return_rate"}],"relationships":[{"cardinality":"many_to_one","from_entity":"order","sql_on":"fact_orders.customer_id = dim_customers.customer_id","to_entity":"customer"},{"cardinality":"many_to_one","from_entity":"order","sql_on":"fact_orders.channel_id = dim_channels.channel_id","to_entity":"channel"},{"cardinality":"many_to_one","from_entity":"order_item","sql_on":"fact_order_items.order_id = fact_orders.order_id","to_entity":"order"},{"cardinality":"many_to_one","from_entity":"order_item","sql_on":"fact_order_items.product_id = dim_products.product_id","to_entity":"product"},{"cardinality":"many_to_one","from_entity":"payment","sql_on":"fact_payments.order_id = fact_orders.order_id","to_entity":"order"},{"cardinality":"many_to_one","from_entity":"return","sql_on":"fact_returns.order_id = fact_order_items.order_id AND fact_returns.line_no = fact_order_items.line_no","to_entity":"order_item"}]}
问题:
将 2026 年已完成订单按金额分层:total_amount 大于等于 2000 为 high,大于等于 1000 且小于 2000 为 medium,其余为 low;输出 order_id、total_amount、amount_band,并按 total_amount 降序、order_id 升序;必须使用 CASE。
规划要求:
plan 只记录输出粒度、数据源、连接、过滤、指标、执行步骤和风险检查;每项保持简短。
SQL 必须严格实现该 plan,并遵循语义层业务口径。
summary 只概括最终做法,assumptions 只列无法由上下文确定的必要假设。
输出必须严格匹配此 JSON Schema:
{"$defs":{"QueryPlan":{"additionalProperties":false,"properties":{"filters":{"items":{"type":"string"},"title":"Filters","type":"array"},"grain":{"title":"Grain","type":"string"},"joins":{"items":{"type":"string"},"title":"Joins","type":"array"},"metrics":{"items":{"type":"string"},"title":"Metrics","type":"array"},"risks":{"items":{"type":"string"},"title":"Risks","type":"array"},"sources":{"items":{"type":"string"},"title":"Sources","type":"array"},"steps":{"items":{"type":"string"},"title":"Steps","type":"array"}},"required":["grain","sources","joins","filters","metrics","steps","risks"],"title":"QueryPlan","type":"object"}},"additionalProperties":false,"properties":{"assumptions":{"items":{"type":"string"},"title":"Assumptions","type":"array"},"plan":{"$ref":"#/$defs/QueryPlan"},"sql":{"title":"Sql","type":"string"},"summary":{"title":"Summary","type":"string"}},"required":["plan","sql","summary","assumptions"],"title":"GenerationOutput","type":"object"}按事件序号排列;密钥和 Authorization 已移除。
历史证据边界:完整 Prompt 已保存,但这次 codex_cli 记录没有保存底层 HTTP 报文或 CLI 参数。本站不会把推测内容伪装成原始请求;未来运行会在 provider.requested 中记录脱敏后的完整调用信封。
SEQ 109{
"isolation_policy_hash": "7c962b44b76369de5a795edbc2504a619f4ac15b62eba4dd5b88e714081115b0",
"status": "running"
}分别显示原始响应、解析结果和 SQL。
{"plan":{"grain":"每行一个 2026 年已完成订单","sources":["fact_orders"],"joins":[],"filters":["status = 'completed'","order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01'"],"metrics":["total_amount","amount_band:>= 2000 为 high,>= 1000 为 medium,其余为 low"],"steps":["筛选 2026 年已完成订单","使用 CASE 计算 amount_band","按 total_amount 降序、order_id 升序排序"],"risks":["CASE 分支须先判断 2000,避免 high 被归为 medium","使用半开日期区间覆盖完整 2026 年"]},"sql":"SELECT\n order_id,\n total_amount,\n CASE\n WHEN total_amount >= 2000 THEN 'high'\n WHEN total_amount >= 1000 THEN 'medium'\n ELSE 'low'\n END AS amount_band\nFROM fact_orders\nWHERE status = 'completed'\n AND order_date >= DATE '2026-01-01'\n AND order_date < DATE '2027-01-01'\nORDER BY total_amount DESC, order_id ASC;","summary":"筛选 2026 年已完成订单,使用 CASE 按订单头金额划分 high、medium、low,并按金额降序及订单编号升序输出。","assumptions":[]}{
"filters": [
"status = 'completed'",
"order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01'"
],
"grain": "每行一个 2026 年已完成订单",
"joins": [],
"metrics": [
"total_amount",
"amount_band:>= 2000 为 high,>= 1000 为 medium,其余为 low"
],
"risks": [
"CASE 分支须先判断 2000,避免 high 被归为 medium",
"使用半开日期区间覆盖完整 2026 年"
],
"sources": [
"fact_orders"
],
"steps": [
"筛选 2026 年已完成订单",
"使用 CASE 计算 amount_band",
"按 total_amount 降序、order_id 升序排序"
]
}SELECT
order_id,
total_amount,
CASE
WHEN total_amount >= 2000 THEN 'high'
WHEN total_amount >= 1000 THEN 'medium'
ELSE 'low'
END AS amount_band
FROM fact_orders
WHERE status = 'completed'
AND order_date >= DATE '2026-01-01'
AND order_date < DATE '2027-01-01'
ORDER BY total_amount DESC, order_id ASC;SELECT
order_id,
total_amount,
CASE
WHEN total_amount >= 2000
THEN 'high'
WHEN total_amount >= 1000
THEN 'medium'
ELSE 'low'
END AS amount_band
FROM fact_orders
WHERE
status = 'completed'
AND order_date >= CAST('2026-01-01' AS DATE)
AND order_date < CAST('2027-01-01' AS DATE)
ORDER BY
total_amount DESC,
order_id ASC{
"token_usage": {
"cache_write_input_tokens": 0,
"cached_input_tokens": 0,
"input_tokens": 19539,
"output_tokens": 316,
"reasoning_output_tokens": 0
},
"generation_ms": null,
"execution_ms": 189.39333299931604
}包含评分明细、参考 SQL、结构要求、比较规则和结果差异。
{
"ast_rules": [
{
"details": {
"actual": 1,
"required": 1
},
"id": "amount-band-case",
"kind": "min_node_count",
"passed": true
}
],
"column_count": 5,
"column_names": 5,
"execution": 10,
"ordering": 10,
"protocol": 5,
"read_only_ast": 5,
"row_f1": 45,
"sql_capability": 15,
"total": 100
}SELECT order_id, total_amount, CASE WHEN total_amount >= 2000 THEN 'high' WHEN total_amount >= 1000 THEN 'medium' ELSE 'low' END AS amount_band FROM fact_orders WHERE status = 'completed' AND order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01' ORDER BY total_amount DESC, order_id ASC[
{
"id": "amount-band-case",
"kind": "min_node_count",
"min": 1,
"node": "Case"
}
]{
"abs_tolerance": "0.005",
"decimal_scale": 2,
"duplicate_policy": "multiset",
"max_rows": 10000,
"rel_tolerance": "0",
"row_order_significant": true
}{
"columns": [
{
"name": "order_id",
"type": "BIGINT"
},
{
"name": "total_amount",
"type": "DECIMAL(14,2)"
},
{
"name": "amount_band",
"type": "VARCHAR"
}
],
"digest": "2a01154f67030cebadd4499ddc6fee2f94d7f8f44ac71c1e9e68feec1b57ca84",
"row_count": 162,
"rows": [
[
562,
"3278.25",
"high"
],
[
157,
"3065.50",
"high"
],
[
497,
"3039.75",
"high"
],
[
529,
"3037.25",
"high"
],
[
315,
"3006.75",
"high"
],
[
287,
"2831.00",
"high"
],
[
93,
"2775.50",
"high"
],
[
36,
"2756.25",
"high"
],
[
44,
"2743.00",
"high"
],
[
238,
"2697.00",
"high"
],
[
255,
"2417.25",
"high"
],
[
206,
"2372.00",
"high"
],
[
503,
"2363.25",
"high"
],
[
38,
"2307.75",
"high"
],
[
144,
"2272.25",
"high"
],
[
526,
"2269.75",
"high"
],
[
368,
"2257.25",
"high"
],
[
105,
"2244.75",
"high"
],
[
356,
"2234.00",
"high"
],
[
202,
"2177.25",
"high"
],
[
27,
"2174.50",
"high"
],
[
597,
"2167.75",
"high"
],
[
272,
"2114.75",
"high"
],
[
258,
"2108.00",
"high"
],
[
62,
"2106.25",
"high"
],
[
159,
"2060.50",
"high"
],
[
279,
"2018.50",
"high"
],
[
98,
"1982.25",
"medium"
],
[
68,
"1975.75",
"medium"
],
[
266,
"1969.00",
"medium"
],
[
172,
"1968.00",
"medium"
],
[
298,
"1951.25",
"medium"
],
[
63,
"1911.25",
"medium"
],
[
523,
"1890.50",
"medium"
],
[
57,
"1888.25",
"medium"
],
[
73,
"1856.50",
"medium"
],
[
393,
"1809.25",
"medium"
],
[
129,
"1798.00",
"medium"
],
[
192,
"1793.75",
"medium"
],
[
578,
"1791.00",
"medium"
],
[
388,
"1789.75",
"medium"
],
[
49,
"1789.00",
"medium"
],
[
405,
"1774.50",
"medium"
],
[
95,
"1770.50",
"medium"
],
[
422,
"1758.00",
"medium"
],
[
459,
"1756.75",
"medium"
],
[
177,
"1732.50",
"medium"
],
[
55,
"1714.25",
"medium"
],
[
229,
"1696.75",
"medium"
],
[
138,
"1695.25",
"medium"
],
[
296,
"1692.00",
"medium"
],
[
193,
"1683.75",
"medium"
],
[
369,
"1667.50",
"medium"
],
[
22,
"1656.25",
"medium"
],
[
486,
"1655.50",
"medium"
],
[
216,
"1628.00",
"medium"
],
[
305,
"1621.75",
"medium"
],
[
508,
"1584.25",
"medium"
],
[
148,
"1496.75",
"medium"
],
[
399,
"1493.00",
"medium"
],
[
267,
"1489.00",
"medium"
],
[
103,
"1464.25",
"medium"
],
[
343,
"1462.50",
"medium"
],
[
478,
"1415.00",
"medium"
],
[
567,
"1409.50",
"medium"
],
[
52,
"1376.75",
"medium"
],
[
243,
"1371.50",
"medium"
],
[
339,
"1368.75",
"medium"
],
[
537,
"1363.25",
"medium"
],
[
594,
"1345.50",
"medium"
],
[
463,
"1342.25",
"medium"
],
[
58,
"1334.25",
"medium"
],
[
357,
"1318.50",
"medium"
],
[
195,
"1309.50",
"medium"
],
[
64,
"1259.25",
"medium"
],
[
367,
"1258.25",
"medium"
],
[
524,
"1255.00",
"medium"
],
[
583,
"1231.00",
"medium"
],
[
316,
"1201.75",
"medium"
],
[
263,
"1199.00",
"medium"
],
[
900001,
"1189.00",
"medium"
],
[
384,
"1175.75",
"medium"
],
[
116,
"1156.25",
"medium"
],
[
244,
"1145.25",
"medium"
],
[
416,
"1138.75",
"medium"
],
[
88,
"1136.25",
"medium"
],
[
359,
"1058.00",
"medium"
],
[
256,
"1045.50",
"medium"
],
[
516,
"1009.75",
"medium"
],
[
75,
"988.75",
"low"
],
[
253,
"971.50",
"low"
],
[
376,
"963.50",
"low"
],
[
559,
"946.75",
"low"
],
[
74,
"928.25",
"low"
],
[
382,
"920.75",
"low"
],
[
467,
"918.75",
"low"
],
[
539,
"911.50",
"low"
],
[
309,
"905.50",
"low"
],
[
464,
"822.75",
"low"
],
[
176,
"804.25",
"low"
],
[
363,
"801.00",
"low"
],
[
149,
"786.25",
"low"
],
[
498,
"759.50",
"low"
],
[
582,
"744.00",
"low"
],
[
84,
"741.25",
"low"
],
[
66,
"710.00",
"low"
],
[
412,
"701.75",
"low"
],
[
169,
"685.75",
"low"
],
[
32,
"680.00",
"low"
],
[
457,
"662.50",
"low"
],
[
69,
"604.75",
"low"
],
[
37,
"597.00",
"low"
],
[
314,
"548.00",
"low"
],
[
168,
"543.25",
"low"
],
[
484,
"531.75",
"low"
],
[
592,
"530.50",
"low"
],
[
517,
"512.50",
"low"
],
[
185,
"499.75",
"low"
],
[
209,
"496.50",
"low"
],
[
286,
"486.75",
"low"
],
[
108,
"482.00",
"low"
],
[
487,
"474.25",
"low"
],
[
85,
"462.75",
"low"
],
[
507,
"453.00",
"low"
],
[
505,
"444.00",
"low"
],
[
219,
"421.25",
"low"
],
[
164,
"416.75",
"low"
],
[
109,
"415.50",
"low"
],
[
318,
"412.75",
"low"
],
[
394,
"378.75",
"low"
],
[
118,
"357.00",
"low"
],
[
353,
"354.50",
"low"
],
[
302,
"341.50",
"low"
],
[
333,
"333.50",
"low"
],
[
439,
"333.50",
"low"
],
[
288,
"322.50",
"low"
],
[
596,
"313.50",
"low"
],
[
175,
"312.00",
"low"
],
[
158,
"310.50",
"low"
],
[
555,
"310.00",
"low"
],
[
322,
"256.50",
"low"
],
[
485,
"245.75",
"low"
],
[
205,
"230.00",
"low"
],
[
214,
"215.75",
"low"
],
[
56,
"198.75",
"low"
],
[
125,
"192.00",
"low"
],
[
226,
"180.50",
"low"
],
[
173,
"174.50",
"low"
],
[
76,
"165.00",
"low"
],
[
385,
"164.75",
"low"
],
[
579,
"135.75",
"low"
],
[
188,
"134.00",
"low"
],
[
139,
"133.00",
"low"
],
[
7,
"131.50",
"low"
],
[
354,
"111.75",
"low"
],
[
900002,
"100.00",
"low"
],
[
900004,
"100.00",
"low"
],
[
522,
"70.50",
"low"
],
[
297,
"65.75",
"low"
],
[
900003,
"50.00",
"low"
],
[
515,
"39.25",
"low"
],
[
348,
"27.00",
"low"
]
]
}{
"columns": [
{
"name": "order_id",
"type": "BIGINT"
},
{
"name": "total_amount",
"type": "DECIMAL(14,2)"
},
{
"name": "amount_band",
"type": "VARCHAR"
}
],
"extra": [],
"missing": [],
"row_count": 162,
"rows": [
[
562,
"3278.25",
"high"
],
[
157,
"3065.50",
"high"
],
[
497,
"3039.75",
"high"
],
[
529,
"3037.25",
"high"
],
[
315,
"3006.75",
"high"
],
[
287,
"2831.00",
"high"
],
[
93,
"2775.50",
"high"
],
[
36,
"2756.25",
"high"
],
[
44,
"2743.00",
"high"
],
[
238,
"2697.00",
"high"
],
[
255,
"2417.25",
"high"
],
[
206,
"2372.00",
"high"
],
[
503,
"2363.25",
"high"
],
[
38,
"2307.75",
"high"
],
[
144,
"2272.25",
"high"
],
[
526,
"2269.75",
"high"
],
[
368,
"2257.25",
"high"
],
[
105,
"2244.75",
"high"
],
[
356,
"2234.00",
"high"
],
[
202,
"2177.25",
"high"
],
[
27,
"2174.50",
"high"
],
[
597,
"2167.75",
"high"
],
[
272,
"2114.75",
"high"
],
[
258,
"2108.00",
"high"
],
[
62,
"2106.25",
"high"
],
[
159,
"2060.50",
"high"
],
[
279,
"2018.50",
"high"
],
[
98,
"1982.25",
"medium"
],
[
68,
"1975.75",
"medium"
],
[
266,
"1969.00",
"medium"
],
[
172,
"1968.00",
"medium"
],
[
298,
"1951.25",
"medium"
],
[
63,
"1911.25",
"medium"
],
[
523,
"1890.50",
"medium"
],
[
57,
"1888.25",
"medium"
],
[
73,
"1856.50",
"medium"
],
[
393,
"1809.25",
"medium"
],
[
129,
"1798.00",
"medium"
],
[
192,
"1793.75",
"medium"
],
[
578,
"1791.00",
"medium"
],
[
388,
"1789.75",
"medium"
],
[
49,
"1789.00",
"medium"
],
[
405,
"1774.50",
"medium"
],
[
95,
"1770.50",
"medium"
],
[
422,
"1758.00",
"medium"
],
[
459,
"1756.75",
"medium"
],
[
177,
"1732.50",
"medium"
],
[
55,
"1714.25",
"medium"
],
[
229,
"1696.75",
"medium"
],
[
138,
"1695.25",
"medium"
],
[
296,
"1692.00",
"medium"
],
[
193,
"1683.75",
"medium"
],
[
369,
"1667.50",
"medium"
],
[
22,
"1656.25",
"medium"
],
[
486,
"1655.50",
"medium"
],
[
216,
"1628.00",
"medium"
],
[
305,
"1621.75",
"medium"
],
[
508,
"1584.25",
"medium"
],
[
148,
"1496.75",
"medium"
],
[
399,
"1493.00",
"medium"
],
[
267,
"1489.00",
"medium"
],
[
103,
"1464.25",
"medium"
],
[
343,
"1462.50",
"medium"
],
[
478,
"1415.00",
"medium"
],
[
567,
"1409.50",
"medium"
],
[
52,
"1376.75",
"medium"
],
[
243,
"1371.50",
"medium"
],
[
339,
"1368.75",
"medium"
],
[
537,
"1363.25",
"medium"
],
[
594,
"1345.50",
"medium"
],
[
463,
"1342.25",
"medium"
],
[
58,
"1334.25",
"medium"
],
[
357,
"1318.50",
"medium"
],
[
195,
"1309.50",
"medium"
],
[
64,
"1259.25",
"medium"
],
[
367,
"1258.25",
"medium"
],
[
524,
"1255.00",
"medium"
],
[
583,
"1231.00",
"medium"
],
[
316,
"1201.75",
"medium"
],
[
263,
"1199.00",
"medium"
],
[
900001,
"1189.00",
"medium"
],
[
384,
"1175.75",
"medium"
],
[
116,
"1156.25",
"medium"
],
[
244,
"1145.25",
"medium"
],
[
416,
"1138.75",
"medium"
],
[
88,
"1136.25",
"medium"
],
[
359,
"1058.00",
"medium"
],
[
256,
"1045.50",
"medium"
],
[
516,
"1009.75",
"medium"
],
[
75,
"988.75",
"low"
],
[
253,
"971.50",
"low"
],
[
376,
"963.50",
"low"
],
[
559,
"946.75",
"low"
],
[
74,
"928.25",
"low"
],
[
382,
"920.75",
"low"
],
[
467,
"918.75",
"low"
],
[
539,
"911.50",
"low"
],
[
309,
"905.50",
"low"
],
[
464,
"822.75",
"low"
],
[
176,
"804.25",
"low"
],
[
363,
"801.00",
"low"
],
[
149,
"786.25",
"low"
],
[
498,
"759.50",
"low"
],
[
582,
"744.00",
"low"
],
[
84,
"741.25",
"low"
],
[
66,
"710.00",
"low"
],
[
412,
"701.75",
"low"
],
[
169,
"685.75",
"low"
],
[
32,
"680.00",
"low"
],
[
457,
"662.50",
"low"
],
[
69,
"604.75",
"low"
],
[
37,
"597.00",
"low"
],
[
314,
"548.00",
"low"
],
[
168,
"543.25",
"low"
],
[
484,
"531.75",
"low"
],
[
592,
"530.50",
"low"
],
[
517,
"512.50",
"low"
],
[
185,
"499.75",
"low"
],
[
209,
"496.50",
"low"
],
[
286,
"486.75",
"low"
],
[
108,
"482.00",
"low"
],
[
487,
"474.25",
"low"
],
[
85,
"462.75",
"low"
],
[
507,
"453.00",
"low"
],
[
505,
"444.00",
"low"
],
[
219,
"421.25",
"low"
],
[
164,
"416.75",
"low"
],
[
109,
"415.50",
"low"
],
[
318,
"412.75",
"low"
],
[
394,
"378.75",
"low"
],
[
118,
"357.00",
"low"
],
[
353,
"354.50",
"low"
],
[
302,
"341.50",
"low"
],
[
333,
"333.50",
"low"
],
[
439,
"333.50",
"low"
],
[
288,
"322.50",
"low"
],
[
596,
"313.50",
"low"
],
[
175,
"312.00",
"low"
],
[
158,
"310.50",
"low"
],
[
555,
"310.00",
"low"
],
[
322,
"256.50",
"low"
],
[
485,
"245.75",
"low"
],
[
205,
"230.00",
"low"
],
[
214,
"215.75",
"low"
],
[
56,
"198.75",
"low"
],
[
125,
"192.00",
"low"
],
[
226,
"180.50",
"low"
],
[
173,
"174.50",
"low"
],
[
76,
"165.00",
"low"
],
[
385,
"164.75",
"low"
],
[
579,
"135.75",
"low"
],
[
188,
"134.00",
"low"
],
[
139,
"133.00",
"low"
],
[
7,
"131.50",
"low"
],
[
354,
"111.75",
"low"
],
[
900002,
"100.00",
"low"
],
[
900004,
"100.00",
"low"
],
[
522,
"70.50",
"low"
],
[
297,
"65.75",
"low"
],
[
900003,
"50.00",
"low"
],
[
515,
"39.25",
"low"
],
[
348,
"27.00",
"low"
]
]
}{
"visible_summary": "筛选 2026 年已完成订单,使用 CASE 按订单头金额划分 high、medium、low,并按金额降序及订单编号升序输出。",
"error_code": null,
"error_message": null,
"expected_digest": "2a01154f67030cebadd4499ddc6fee2f94d7f8f44ac71c1e9e68feec1b57ca84",
"actual_digest": "fbfb40370360036545e421d141aa11e844e2b3076d821f25823817eb60cfb431",
"assumptions": []
}按全局事件序号排列,保留时间、级别、类型、消息和 payload。
SEQ 107case.startedinfo{
"status": "generating"
}SEQ 108prompt.builtinfo{
"status": "completed"
}SEQ 109provider.requestedinfo{
"isolation_policy_hash": "7c962b44b76369de5a795edbc2504a619f4ac15b62eba4dd5b88e714081115b0",
"status": "running"
}SEQ 110provider.deltainfo{
"text": "{\"plan\":{\"grain\":\"每行一个 2026 年已完成订单\",\"sources\":[\"fact_orders\"],\"joins\":[],\"filters\":[\"status = 'completed'\",\"order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01'\"],\"metrics\":[\"total_amount\",\"amount_band:>= 2000 为 high,>= 1000 为 medium,其余为 low\"],\"steps\":[\"筛选 2026 年已完成订单\",\"使用 CASE 计算 amount_band\",\"按 total_amount 降序、order_id 升序排序\"],\"risks\":[\"CASE 分支须先判断 2000,避免 high 被归为 medium\",\"使用半开日期区间覆盖完整 2026 年\"]},\"sql\":\"SELECT\\n order_id,\\n total_amount,\\n CASE\\n WHEN total_amount >= 2000 THEN 'high'\\n WHEN total_amount >= 1000 THEN 'medium'\\n ELSE 'low'\\n END AS amount_band\\nFROM fact_orders\\nWHERE status = 'completed'\\n AND order_date >= DATE '2026-01-01'\\n AND order_date < DATE '2027-01-01'\\nORDER BY total_amount DESC, order_id ASC;\",\"summary\":\"筛选 2026 年已完成订单,使用 CASE 按订单头金额划分 high、medium、low,并按金额降序及订单编号升序输出。\",\"assumptions\":[]}"
}SEQ 111provider.completedinfo{
"elapsed_ms": 19190.03537500248,
"status": "completed",
"token_usage": {
"cache_write_input_tokens": 0,
"cached_input_tokens": 0,
"input_tokens": 19539,
"output_tokens": 316,
"reasoning_output_tokens": 0
}
}SEQ 112plan.completedinfo{
"grain": "每行一个 2026 年已完成订单",
"status": "completed",
"steps": 3
}SEQ 113sql.parsedinfo{
"status": "completed"
}SEQ 114score.completedinfo{
"score": 100,
"status": "completed"
}完整 JSON 字段,不经过页面裁剪。
{
"actual_digest": "fbfb40370360036545e421d141aa11e844e2b3076d821f25823817eb60cfb431",
"assumptions": [],
"attempt": 1,
"category": "case_expression",
"comparison": {
"abs_tolerance": "0.005",
"decimal_scale": 2,
"duplicate_policy": "multiset",
"max_rows": 10000,
"rel_tolerance": "0",
"row_order_significant": true
},
"difficulty": "easy",
"error_code": null,
"error_message": null,
"execution_ms": 189.39333299931604,
"expected_digest": "2a01154f67030cebadd4499ddc6fee2f94d7f8f44ac71c1e9e68feec1b57ca84",
"expected_result_preview": {
"columns": [
{
"name": "order_id",
"type": "BIGINT"
},
{
"name": "total_amount",
"type": "DECIMAL(14,2)"
},
{
"name": "amount_band",
"type": "VARCHAR"
}
],
"digest": "2a01154f67030cebadd4499ddc6fee2f94d7f8f44ac71c1e9e68feec1b57ca84",
"row_count": 162,
"rows": [
[
562,
"3278.25",
"high"
],
[
157,
"3065.50",
"high"
],
[
497,
"3039.75",
"high"
],
[
529,
"3037.25",
"high"
],
[
315,
"3006.75",
"high"
],
[
287,
"2831.00",
"high"
],
[
93,
"2775.50",
"high"
],
[
36,
"2756.25",
"high"
],
[
44,
"2743.00",
"high"
],
[
238,
"2697.00",
"high"
],
[
255,
"2417.25",
"high"
],
[
206,
"2372.00",
"high"
],
[
503,
"2363.25",
"high"
],
[
38,
"2307.75",
"high"
],
[
144,
"2272.25",
"high"
],
[
526,
"2269.75",
"high"
],
[
368,
"2257.25",
"high"
],
[
105,
"2244.75",
"high"
],
[
356,
"2234.00",
"high"
],
[
202,
"2177.25",
"high"
],
[
27,
"2174.50",
"high"
],
[
597,
"2167.75",
"high"
],
[
272,
"2114.75",
"high"
],
[
258,
"2108.00",
"high"
],
[
62,
"2106.25",
"high"
],
[
159,
"2060.50",
"high"
],
[
279,
"2018.50",
"high"
],
[
98,
"1982.25",
"medium"
],
[
68,
"1975.75",
"medium"
],
[
266,
"1969.00",
"medium"
],
[
172,
"1968.00",
"medium"
],
[
298,
"1951.25",
"medium"
],
[
63,
"1911.25",
"medium"
],
[
523,
"1890.50",
"medium"
],
[
57,
"1888.25",
"medium"
],
[
73,
"1856.50",
"medium"
],
[
393,
"1809.25",
"medium"
],
[
129,
"1798.00",
"medium"
],
[
192,
"1793.75",
"medium"
],
[
578,
"1791.00",
"medium"
],
[
388,
"1789.75",
"medium"
],
[
49,
"1789.00",
"medium"
],
[
405,
"1774.50",
"medium"
],
[
95,
"1770.50",
"medium"
],
[
422,
"1758.00",
"medium"
],
[
459,
"1756.75",
"medium"
],
[
177,
"1732.50",
"medium"
],
[
55,
"1714.25",
"medium"
],
[
229,
"1696.75",
"medium"
],
[
138,
"1695.25",
"medium"
],
[
296,
"1692.00",
"medium"
],
[
193,
"1683.75",
"medium"
],
[
369,
"1667.50",
"medium"
],
[
22,
"1656.25",
"medium"
],
[
486,
"1655.50",
"medium"
],
[
216,
"1628.00",
"medium"
],
[
305,
"1621.75",
"medium"
],
[
508,
"1584.25",
"medium"
],
[
148,
"1496.75",
"medium"
],
[
399,
"1493.00",
"medium"
],
[
267,
"1489.00",
"medium"
],
[
103,
"1464.25",
"medium"
],
[
343,
"1462.50",
"medium"
],
[
478,
"1415.00",
"medium"
],
[
567,
"1409.50",
"medium"
],
[
52,
"1376.75",
"medium"
],
[
243,
"1371.50",
"medium"
],
[
339,
"1368.75",
"medium"
],
[
537,
"1363.25",
"medium"
],
[
594,
"1345.50",
"medium"
],
[
463,
"1342.25",
"medium"
],
[
58,
"1334.25",
"medium"
],
[
357,
"1318.50",
"medium"
],
[
195,
"1309.50",
"medium"
],
[
64,
"1259.25",
"medium"
],
[
367,
"1258.25",
"medium"
],
[
524,
"1255.00",
"medium"
],
[
583,
"1231.00",
"medium"
],
[
316,
"1201.75",
"medium"
],
[
263,
"1199.00",
"medium"
],
[
900001,
"1189.00",
"medium"
],
[
384,
"1175.75",
"medium"
],
[
116,
"1156.25",
"medium"
],
[
244,
"1145.25",
"medium"
],
[
416,
"1138.75",
"medium"
],
[
88,
"1136.25",
"medium"
],
[
359,
"1058.00",
"medium"
],
[
256,
"1045.50",
"medium"
],
[
516,
"1009.75",
"medium"
],
[
75,
"988.75",
"low"
],
[
253,
"971.50",
"low"
],
[
376,
"963.50",
"low"
],
[
559,
"946.75",
"low"
],
[
74,
"928.25",
"low"
],
[
382,
"920.75",
"low"
],
[
467,
"918.75",
"low"
],
[
539,
"911.50",
"low"
],
[
309,
"905.50",
"low"
],
[
464,
"822.75",
"low"
],
[
176,
"804.25",
"low"
],
[
363,
"801.00",
"low"
],
[
149,
"786.25",
"low"
],
[
498,
"759.50",
"low"
],
[
582,
"744.00",
"low"
],
[
84,
"741.25",
"low"
],
[
66,
"710.00",
"low"
],
[
412,
"701.75",
"low"
],
[
169,
"685.75",
"low"
],
[
32,
"680.00",
"low"
],
[
457,
"662.50",
"low"
],
[
69,
"604.75",
"low"
],
[
37,
"597.00",
"low"
],
[
314,
"548.00",
"low"
],
[
168,
"543.25",
"low"
],
[
484,
"531.75",
"low"
],
[
592,
"530.50",
"low"
],
[
517,
"512.50",
"low"
],
[
185,
"499.75",
"low"
],
[
209,
"496.50",
"low"
],
[
286,
"486.75",
"low"
],
[
108,
"482.00",
"low"
],
[
487,
"474.25",
"low"
],
[
85,
"462.75",
"low"
],
[
507,
"453.00",
"low"
],
[
505,
"444.00",
"low"
],
[
219,
"421.25",
"low"
],
[
164,
"416.75",
"low"
],
[
109,
"415.50",
"low"
],
[
318,
"412.75",
"low"
],
[
394,
"378.75",
"low"
],
[
118,
"357.00",
"low"
],
[
353,
"354.50",
"low"
],
[
302,
"341.50",
"low"
],
[
333,
"333.50",
"low"
],
[
439,
"333.50",
"low"
],
[
288,
"322.50",
"low"
],
[
596,
"313.50",
"low"
],
[
175,
"312.00",
"low"
],
[
158,
"310.50",
"low"
],
[
555,
"310.00",
"low"
],
[
322,
"256.50",
"low"
],
[
485,
"245.75",
"low"
],
[
205,
"230.00",
"low"
],
[
214,
"215.75",
"low"
],
[
56,
"198.75",
"low"
],
[
125,
"192.00",
"low"
],
[
226,
"180.50",
"low"
],
[
173,
"174.50",
"low"
],
[
76,
"165.00",
"low"
],
[
385,
"164.75",
"low"
],
[
579,
"135.75",
"low"
],
[
188,
"134.00",
"low"
],
[
139,
"133.00",
"low"
],
[
7,
"131.50",
"low"
],
[
354,
"111.75",
"low"
],
[
900002,
"100.00",
"low"
],
[
900004,
"100.00",
"low"
],
[
522,
"70.50",
"low"
],
[
297,
"65.75",
"low"
],
[
900003,
"50.00",
"low"
],
[
515,
"39.25",
"low"
],
[
348,
"27.00",
"low"
]
]
},
"finished_at": "2026-08-29T22:52:48.013976",
"formatted_sql": "SELECT\n order_id,\n total_amount,\n CASE\n WHEN total_amount >= 2000\n THEN 'high'\n WHEN total_amount >= 1000\n THEN 'medium'\n ELSE 'low'\n END AS amount_band\nFROM fact_orders\nWHERE\n status = 'completed'\n AND order_date >= CAST('2026-01-01' AS DATE)\n AND order_date < CAST('2027-01-01' AS DATE)\nORDER BY\n total_amount DESC,\n order_id ASC",
"generated_sql": "SELECT\n order_id,\n total_amount,\n CASE\n WHEN total_amount >= 2000 THEN 'high'\n WHEN total_amount >= 1000 THEN 'medium'\n ELSE 'low'\n END AS amount_band\nFROM fact_orders\nWHERE status = 'completed'\n AND order_date >= DATE '2026-01-01'\n AND order_date < DATE '2027-01-01'\nORDER BY total_amount DESC, order_id ASC;",
"generation_ms": null,
"id": 159,
"model_name": "Sol 本机实测",
"model_run_id": 22,
"plan": {
"filters": [
"status = 'completed'",
"order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01'"
],
"grain": "每行一个 2026 年已完成订单",
"joins": [],
"metrics": [
"total_amount",
"amount_band:>= 2000 为 high,>= 1000 为 medium,其余为 low"
],
"risks": [
"CASE 分支须先判断 2000,避免 high 被归为 medium",
"使用半开日期区间覆盖完整 2026 年"
],
"sources": [
"fact_orders"
],
"steps": [
"筛选 2026 年已完成订单",
"使用 CASE 计算 amount_band",
"按 total_amount 降序、order_id 升序排序"
]
},
"prompt": "你是 Text-to-SQL 数据分析与数据开发生成器。先形成简洁、可审计的结构化查询方案,再生成完成问题所需的 SQL;不要输出隐藏推理。\n\n方言与安全规则:\nUse DuckDB SQL. Return exactly one read-only query. Do not access files, URLs, extensions, or schemas outside the supplied tables.\n\n数据库结构:\n{\"semantic_relationships\":[{\"cardinality\":\"many_to_one\",\"from_entity\":\"order\",\"sql_on\":\"fact_orders.customer_id = dim_customers.customer_id\",\"to_entity\":\"customer\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"order\",\"sql_on\":\"fact_orders.channel_id = dim_channels.channel_id\",\"to_entity\":\"channel\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"order_item\",\"sql_on\":\"fact_order_items.order_id = fact_orders.order_id\",\"to_entity\":\"order\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"order_item\",\"sql_on\":\"fact_order_items.product_id = dim_products.product_id\",\"to_entity\":\"product\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"payment\",\"sql_on\":\"fact_payments.order_id = fact_orders.order_id\",\"to_entity\":\"order\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"return\",\"sql_on\":\"fact_returns.order_id = fact_order_items.order_id AND fact_returns.line_no = fact_order_items.line_no\",\"to_entity\":\"order_item\"}],\"tables\":[{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"channel_id\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"channel_name\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"channel_type\",\"nullable\":false}],\"foreign_keys\":[],\"name\":\"dim_channels\",\"primary_key\":[\"channel_id\"]},{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"customer_id\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"customer_name\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"city\",\"nullable\":true},{\"data_type\":\"DATE\",\"name\":\"signup_date\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"segment\",\"nullable\":false}],\"foreign_keys\":[],\"name\":\"dim_customers\",\"primary_key\":[\"customer_id\"]},{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"product_id\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"product_name\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"category\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"brand\",\"nullable\":false},{\"data_type\":\"DECIMAL(14,2)\",\"name\":\"list_price\",\"nullable\":false}],\"foreign_keys\":[],\"name\":\"dim_products\",\"primary_key\":[\"product_id\"]},{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"order_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"line_no\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"product_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"quantity\",\"nullable\":false},{\"data_type\":\"DECIMAL(14,2)\",\"name\":\"unit_price\",\"nullable\":false},{\"data_type\":\"DECIMAL(14,2)\",\"name\":\"discount_amount\",\"nullable\":false}],\"foreign_keys\":[{\"columns\":[\"order_id\"],\"referenced_columns\":[\"order_id\"],\"referenced_table\":\"fact_orders\"},{\"columns\":[\"product_id\"],\"referenced_columns\":[\"product_id\"],\"referenced_table\":\"dim_products\"}],\"name\":\"fact_order_items\",\"primary_key\":[\"order_id\",\"line_no\"]},{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"order_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"customer_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"channel_id\",\"nullable\":false},{\"data_type\":\"DATE\",\"name\":\"order_date\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"status\",\"nullable\":false},{\"data_type\":\"DECIMAL(14,2)\",\"name\":\"total_amount\",\"nullable\":false}],\"foreign_keys\":[{\"columns\":[\"customer_id\"],\"referenced_columns\":[\"customer_id\"],\"referenced_table\":\"dim_customers\"},{\"columns\":[\"channel_id\"],\"referenced_columns\":[\"channel_id\"],\"referenced_table\":\"dim_channels\"}],\"name\":\"fact_orders\",\"primary_key\":[\"order_id\"]},{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"payment_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"order_id\",\"nullable\":false},{\"data_type\":\"TIMESTAMP\",\"name\":\"paid_at\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"payment_method\",\"nullable\":false},{\"data_type\":\"DECIMAL(14,2)\",\"name\":\"amount\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"status\",\"nullable\":false}],\"foreign_keys\":[{\"columns\":[\"order_id\"],\"referenced_columns\":[\"order_id\"],\"referenced_table\":\"fact_orders\"}],\"name\":\"fact_payments\",\"primary_key\":[\"payment_id\"]},{\"columns\":[{\"data_type\":\"BIGINT\",\"name\":\"return_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"order_id\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"line_no\",\"nullable\":false},{\"data_type\":\"TIMESTAMP\",\"name\":\"returned_at\",\"nullable\":false},{\"data_type\":\"BIGINT\",\"name\":\"return_qty\",\"nullable\":false},{\"data_type\":\"DECIMAL(14,2)\",\"name\":\"refund_amount\",\"nullable\":false},{\"data_type\":\"VARCHAR\",\"name\":\"reason\",\"nullable\":true}],\"foreign_keys\":[{\"columns\":[\"order_id\",\"line_no\"],\"referenced_columns\":[\"order_id\",\"line_no\"],\"referenced_table\":\"fact_order_items\"}],\"name\":\"fact_returns\",\"primary_key\":[\"return_id\"]}]}\n\n语义层与业务口径:\n{\"business_rules\":[\"完成订单仅指 fact_orders.status = 'completed'。\",\"净销售额为 quantity * unit_price - discount_amount。\",\"paid、refunded、failed 金额只按 fact_payments.status 分类。\",\"退货率为完成订单的 returned_qty / sold_qty,售出数量仅含完成订单。\",\"月份按 UTC Gregorian calendar 计算。\",\"订单头 total_amount 应等于订单行净额汇总,差异视为数据质量异常。\"],\"dimensions\":[{\"data_type\":\"VARCHAR\",\"description\":\"客户分群\",\"expression\":\"dim_customers.segment\",\"name\":\"customer_segment\"},{\"data_type\":\"VARCHAR\",\"description\":\"商品品类\",\"expression\":\"dim_products.category\",\"name\":\"product_category\"},{\"data_type\":\"VARCHAR\",\"description\":\"渠道类型\",\"expression\":\"dim_channels.channel_type\",\"name\":\"channel_type\"},{\"data_type\":\"VARCHAR\",\"description\":\"UTC Gregorian 月份\",\"expression\":\"strftime(fact_orders.order_date, '%Y-%m')\",\"name\":\"order_month\"}],\"entities\":[{\"description\":\"客户主数据\",\"grain\":\"每行一个客户\",\"name\":\"customer\",\"primary_key\":[\"customer_id\"],\"table\":\"dim_customers\"},{\"description\":\"商品主数据\",\"grain\":\"每行一个商品\",\"name\":\"product\",\"primary_key\":[\"product_id\"],\"table\":\"dim_products\"},{\"description\":\"渠道主数据\",\"grain\":\"每行一个渠道\",\"name\":\"channel\",\"primary_key\":[\"channel_id\"],\"table\":\"dim_channels\"},{\"description\":\"订单头\",\"grain\":\"每行一个订单\",\"name\":\"order\",\"primary_key\":[\"order_id\"],\"table\":\"fact_orders\"},{\"description\":\"订单行\",\"grain\":\"每行一个订单商品行\",\"name\":\"order_item\",\"primary_key\":[\"order_id\",\"line_no\"],\"table\":\"fact_order_items\"},{\"description\":\"支付尝试\",\"grain\":\"每行一笔支付\",\"name\":\"payment\",\"primary_key\":[\"payment_id\"],\"table\":\"fact_payments\"},{\"description\":\"退货记录\",\"grain\":\"每行一条订单行退货\",\"name\":\"return\",\"primary_key\":[\"return_id\"],\"table\":\"fact_returns\"}],\"metrics\":[{\"description\":\"已完成订单数\",\"expression\":\"COUNT(DISTINCT CASE WHEN fact_orders.status = 'completed' THEN fact_orders.order_id END)\",\"filters\":[\"fact_orders.status = 'completed'\"],\"grain\":\"聚合\",\"name\":\"completed_order_count\"},{\"description\":\"完成订单商品行净销售额\",\"expression\":\"SUM(fact_order_items.quantity * fact_order_items.unit_price - fact_order_items.discount_amount)\",\"filters\":[\"fact_orders.status = 'completed'\"],\"grain\":\"聚合\",\"name\":\"net_revenue\"},{\"description\":\"成功支付金额\",\"expression\":\"SUM(CASE WHEN fact_payments.status = 'paid' THEN fact_payments.amount ELSE 0 END)\",\"filters\":[],\"grain\":\"聚合\",\"name\":\"paid_amount\"},{\"description\":\"退款状态支付金额\",\"expression\":\"SUM(CASE WHEN fact_payments.status = 'refunded' THEN fact_payments.amount ELSE 0 END)\",\"filters\":[],\"grain\":\"聚合\",\"name\":\"refunded_amount\"},{\"description\":\"失败支付金额\",\"expression\":\"SUM(CASE WHEN fact_payments.status = 'failed' THEN fact_payments.amount ELSE 0 END)\",\"filters\":[],\"grain\":\"聚合\",\"name\":\"failed_amount\"},{\"description\":\"完成订单退货数量除以售出数量\",\"expression\":\"SUM(fact_returns.return_qty) / SUM(fact_order_items.quantity)\",\"filters\":[\"fact_orders.status = 'completed'\"],\"grain\":\"聚合\",\"name\":\"return_rate\"}],\"relationships\":[{\"cardinality\":\"many_to_one\",\"from_entity\":\"order\",\"sql_on\":\"fact_orders.customer_id = dim_customers.customer_id\",\"to_entity\":\"customer\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"order\",\"sql_on\":\"fact_orders.channel_id = dim_channels.channel_id\",\"to_entity\":\"channel\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"order_item\",\"sql_on\":\"fact_order_items.order_id = fact_orders.order_id\",\"to_entity\":\"order\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"order_item\",\"sql_on\":\"fact_order_items.product_id = dim_products.product_id\",\"to_entity\":\"product\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"payment\",\"sql_on\":\"fact_payments.order_id = fact_orders.order_id\",\"to_entity\":\"order\"},{\"cardinality\":\"many_to_one\",\"from_entity\":\"return\",\"sql_on\":\"fact_returns.order_id = fact_order_items.order_id AND fact_returns.line_no = fact_order_items.line_no\",\"to_entity\":\"order_item\"}]}\n\n问题:\n将 2026 年已完成订单按金额分层:total_amount 大于等于 2000 为 high,大于等于 1000 且小于 2000 为 medium,其余为 low;输出 order_id、total_amount、amount_band,并按 total_amount 降序、order_id 升序;必须使用 CASE。\n\n规划要求:\nplan 只记录输出粒度、数据源、连接、过滤、指标、执行步骤和风险检查;每项保持简短。\nSQL 必须严格实现该 plan,并遵循语义层业务口径。\nsummary 只概括最终做法,assumptions 只列无法由上下文确定的必要假设。\n输出必须严格匹配此 JSON Schema:\n{\"$defs\":{\"QueryPlan\":{\"additionalProperties\":false,\"properties\":{\"filters\":{\"items\":{\"type\":\"string\"},\"title\":\"Filters\",\"type\":\"array\"},\"grain\":{\"title\":\"Grain\",\"type\":\"string\"},\"joins\":{\"items\":{\"type\":\"string\"},\"title\":\"Joins\",\"type\":\"array\"},\"metrics\":{\"items\":{\"type\":\"string\"},\"title\":\"Metrics\",\"type\":\"array\"},\"risks\":{\"items\":{\"type\":\"string\"},\"title\":\"Risks\",\"type\":\"array\"},\"sources\":{\"items\":{\"type\":\"string\"},\"title\":\"Sources\",\"type\":\"array\"},\"steps\":{\"items\":{\"type\":\"string\"},\"title\":\"Steps\",\"type\":\"array\"}},\"required\":[\"grain\",\"sources\",\"joins\",\"filters\",\"metrics\",\"steps\",\"risks\"],\"title\":\"QueryPlan\",\"type\":\"object\"}},\"additionalProperties\":false,\"properties\":{\"assumptions\":{\"items\":{\"type\":\"string\"},\"title\":\"Assumptions\",\"type\":\"array\"},\"plan\":{\"$ref\":\"#/$defs/QueryPlan\"},\"sql\":{\"title\":\"Sql\",\"type\":\"string\"},\"summary\":{\"title\":\"Summary\",\"type\":\"string\"}},\"required\":[\"plan\",\"sql\",\"summary\",\"assumptions\"],\"title\":\"GenerationOutput\",\"type\":\"object\"}",
"provider_request_id": null,
"question": "将 2026 年已完成订单按金额分层:total_amount 大于等于 2000 为 high,大于等于 1000 且小于 2000 为 medium,其余为 low;输出 order_id、total_amount、amount_band,并按 total_amount 降序、order_id 升序;必须使用 CASE。",
"radar_dimension": "基础查询",
"raw_output": "{\"plan\":{\"grain\":\"每行一个 2026 年已完成订单\",\"sources\":[\"fact_orders\"],\"joins\":[],\"filters\":[\"status = 'completed'\",\"order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01'\"],\"metrics\":[\"total_amount\",\"amount_band:>= 2000 为 high,>= 1000 为 medium,其余为 low\"],\"steps\":[\"筛选 2026 年已完成订单\",\"使用 CASE 计算 amount_band\",\"按 total_amount 降序、order_id 升序排序\"],\"risks\":[\"CASE 分支须先判断 2000,避免 high 被归为 medium\",\"使用半开日期区间覆盖完整 2026 年\"]},\"sql\":\"SELECT\\n order_id,\\n total_amount,\\n CASE\\n WHEN total_amount >= 2000 THEN 'high'\\n WHEN total_amount >= 1000 THEN 'medium'\\n ELSE 'low'\\n END AS amount_band\\nFROM fact_orders\\nWHERE status = 'completed'\\n AND order_date >= DATE '2026-01-01'\\n AND order_date < DATE '2027-01-01'\\nORDER BY total_amount DESC, order_id ASC;\",\"summary\":\"筛选 2026 年已完成订单,使用 CASE 按订单头金额划分 high、medium、low,并按金额降序及订单编号升序输出。\",\"assumptions\":[]}",
"reference_sql": "SELECT order_id, total_amount, CASE WHEN total_amount >= 2000 THEN 'high' WHEN total_amount >= 1000 THEN 'medium' ELSE 'low' END AS amount_band FROM fact_orders WHERE status = 'completed' AND order_date >= DATE '2026-01-01' AND order_date < DATE '2027-01-01' ORDER BY total_amount DESC, order_id ASC",
"requested_model_id": "gpt-5.6-sol",
"required_ast": [
{
"id": "amount-band-case",
"kind": "min_node_count",
"min": 1,
"node": "Case"
}
],
"resolved_model_id": "gpt-5.6-sol",
"result_preview": {
"columns": [
{
"name": "order_id",
"type": "BIGINT"
},
{
"name": "total_amount",
"type": "DECIMAL(14,2)"
},
{
"name": "amount_band",
"type": "VARCHAR"
}
],
"extra": [],
"missing": [],
"row_count": 162,
"rows": [
[
562,
"3278.25",
"high"
],
[
157,
"3065.50",
"high"
],
[
497,
"3039.75",
"high"
],
[
529,
"3037.25",
"high"
],
[
315,
"3006.75",
"high"
],
[
287,
"2831.00",
"high"
],
[
93,
"2775.50",
"high"
],
[
36,
"2756.25",
"high"
],
[
44,
"2743.00",
"high"
],
[
238,
"2697.00",
"high"
],
[
255,
"2417.25",
"high"
],
[
206,
"2372.00",
"high"
],
[
503,
"2363.25",
"high"
],
[
38,
"2307.75",
"high"
],
[
144,
"2272.25",
"high"
],
[
526,
"2269.75",
"high"
],
[
368,
"2257.25",
"high"
],
[
105,
"2244.75",
"high"
],
[
356,
"2234.00",
"high"
],
[
202,
"2177.25",
"high"
],
[
27,
"2174.50",
"high"
],
[
597,
"2167.75",
"high"
],
[
272,
"2114.75",
"high"
],
[
258,
"2108.00",
"high"
],
[
62,
"2106.25",
"high"
],
[
159,
"2060.50",
"high"
],
[
279,
"2018.50",
"high"
],
[
98,
"1982.25",
"medium"
],
[
68,
"1975.75",
"medium"
],
[
266,
"1969.00",
"medium"
],
[
172,
"1968.00",
"medium"
],
[
298,
"1951.25",
"medium"
],
[
63,
"1911.25",
"medium"
],
[
523,
"1890.50",
"medium"
],
[
57,
"1888.25",
"medium"
],
[
73,
"1856.50",
"medium"
],
[
393,
"1809.25",
"medium"
],
[
129,
"1798.00",
"medium"
],
[
192,
"1793.75",
"medium"
],
[
578,
"1791.00",
"medium"
],
[
388,
"1789.75",
"medium"
],
[
49,
"1789.00",
"medium"
],
[
405,
"1774.50",
"medium"
],
[
95,
"1770.50",
"medium"
],
[
422,
"1758.00",
"medium"
],
[
459,
"1756.75",
"medium"
],
[
177,
"1732.50",
"medium"
],
[
55,
"1714.25",
"medium"
],
[
229,
"1696.75",
"medium"
],
[
138,
"1695.25",
"medium"
],
[
296,
"1692.00",
"medium"
],
[
193,
"1683.75",
"medium"
],
[
369,
"1667.50",
"medium"
],
[
22,
"1656.25",
"medium"
],
[
486,
"1655.50",
"medium"
],
[
216,
"1628.00",
"medium"
],
[
305,
"1621.75",
"medium"
],
[
508,
"1584.25",
"medium"
],
[
148,
"1496.75",
"medium"
],
[
399,
"1493.00",
"medium"
],
[
267,
"1489.00",
"medium"
],
[
103,
"1464.25",
"medium"
],
[
343,
"1462.50",
"medium"
],
[
478,
"1415.00",
"medium"
],
[
567,
"1409.50",
"medium"
],
[
52,
"1376.75",
"medium"
],
[
243,
"1371.50",
"medium"
],
[
339,
"1368.75",
"medium"
],
[
537,
"1363.25",
"medium"
],
[
594,
"1345.50",
"medium"
],
[
463,
"1342.25",
"medium"
],
[
58,
"1334.25",
"medium"
],
[
357,
"1318.50",
"medium"
],
[
195,
"1309.50",
"medium"
],
[
64,
"1259.25",
"medium"
],
[
367,
"1258.25",
"medium"
],
[
524,
"1255.00",
"medium"
],
[
583,
"1231.00",
"medium"
],
[
316,
"1201.75",
"medium"
],
[
263,
"1199.00",
"medium"
],
[
900001,
"1189.00",
"medium"
],
[
384,
"1175.75",
"medium"
],
[
116,
"1156.25",
"medium"
],
[
244,
"1145.25",
"medium"
],
[
416,
"1138.75",
"medium"
],
[
88,
"1136.25",
"medium"
],
[
359,
"1058.00",
"medium"
],
[
256,
"1045.50",
"medium"
],
[
516,
"1009.75",
"medium"
],
[
75,
"988.75",
"low"
],
[
253,
"971.50",
"low"
],
[
376,
"963.50",
"low"
],
[
559,
"946.75",
"low"
],
[
74,
"928.25",
"low"
],
[
382,
"920.75",
"low"
],
[
467,
"918.75",
"low"
],
[
539,
"911.50",
"low"
],
[
309,
"905.50",
"low"
],
[
464,
"822.75",
"low"
],
[
176,
"804.25",
"low"
],
[
363,
"801.00",
"low"
],
[
149,
"786.25",
"low"
],
[
498,
"759.50",
"low"
],
[
582,
"744.00",
"low"
],
[
84,
"741.25",
"low"
],
[
66,
"710.00",
"low"
],
[
412,
"701.75",
"low"
],
[
169,
"685.75",
"low"
],
[
32,
"680.00",
"low"
],
[
457,
"662.50",
"low"
],
[
69,
"604.75",
"low"
],
[
37,
"597.00",
"low"
],
[
314,
"548.00",
"low"
],
[
168,
"543.25",
"low"
],
[
484,
"531.75",
"low"
],
[
592,
"530.50",
"low"
],
[
517,
"512.50",
"low"
],
[
185,
"499.75",
"low"
],
[
209,
"496.50",
"low"
],
[
286,
"486.75",
"low"
],
[
108,
"482.00",
"low"
],
[
487,
"474.25",
"low"
],
[
85,
"462.75",
"low"
],
[
507,
"453.00",
"low"
],
[
505,
"444.00",
"low"
],
[
219,
"421.25",
"low"
],
[
164,
"416.75",
"low"
],
[
109,
"415.50",
"low"
],
[
318,
"412.75",
"low"
],
[
394,
"378.75",
"low"
],
[
118,
"357.00",
"low"
],
[
353,
"354.50",
"low"
],
[
302,
"341.50",
"low"
],
[
333,
"333.50",
"low"
],
[
439,
"333.50",
"low"
],
[
288,
"322.50",
"low"
],
[
596,
"313.50",
"low"
],
[
175,
"312.00",
"low"
],
[
158,
"310.50",
"low"
],
[
555,
"310.00",
"low"
],
[
322,
"256.50",
"low"
],
[
485,
"245.75",
"low"
],
[
205,
"230.00",
"low"
],
[
214,
"215.75",
"low"
],
[
56,
"198.75",
"low"
],
[
125,
"192.00",
"low"
],
[
226,
"180.50",
"low"
],
[
173,
"174.50",
"low"
],
[
76,
"165.00",
"low"
],
[
385,
"164.75",
"low"
],
[
579,
"135.75",
"low"
],
[
188,
"134.00",
"low"
],
[
139,
"133.00",
"low"
],
[
7,
"131.50",
"low"
],
[
354,
"111.75",
"low"
],
[
900002,
"100.00",
"low"
],
[
900004,
"100.00",
"low"
],
[
522,
"70.50",
"low"
],
[
297,
"65.75",
"low"
],
[
900003,
"50.00",
"low"
],
[
515,
"39.25",
"low"
],
[
348,
"27.00",
"low"
]
]
},
"run_id": 18,
"score": {
"ast_rules": [
{
"details": {
"actual": 1,
"required": 1
},
"id": "amount-band-case",
"kind": "min_node_count",
"passed": true
}
],
"column_count": 5,
"column_names": 5,
"execution": 10,
"ordering": 10,
"protocol": 5,
"read_only_ast": 5,
"row_f1": 45,
"sql_capability": 15,
"total": 100
},
"stable_key": "completed_order_amount_band",
"started_at": "2026-08-29T22:52:28.608301",
"status": "completed",
"suite_content_hash": "5b5d98876ea35114f18ce6dfa48cc9800d88b6baba80d311b2f52552a38b31af",
"title": "已完成订单金额分层",
"token_usage": {
"cache_write_input_tokens": 0,
"cached_input_tokens": 0,
"input_tokens": 19539,
"output_tokens": 316,
"reasoning_output_tokens": 0
},
"visible_summary": "筛选 2026 年已完成订单,使用 CASE 按订单头金额划分 high、medium、low,并按金额降序及订单编号升序输出。"
}