[
  {
    "question": "最近7天各服务区的总收入和订单总数是多少？按收入降序排列。",
    "sql": "SELECT service_name AS 服务区名称, SUM(pay_sum) AS 总收入, SUM(order_sum) AS 订单总数 FROM bss_business_day_data WHERE oper_date >= CURRENT_DATE - INTERVAL '7 days' AND delete_ts IS NULL GROUP BY service_name ORDER BY 总收入 DESC;"
  },
  {
    "question": "昨日各档口的微信支付金额占比（占该档口总支付金额）是多少？仅显示占比超过50%的记录。",
    "sql": "SELECT branch_name AS 档口名称, (wx / pay_sum * 100)::numeric(5,2) AS 微信支付占比 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE - INTERVAL '1 day' AND pay_sum > 0 AND delete_ts IS NULL GROUP BY branch_name, wx, pay_sum HAVING (wx / pay_sum * 100) > 50 ORDER BY 微信支付占比 DESC;"
  },
  {
    "question": "过去30天内日均订单数最高的前5个服务区是哪些？",
    "sql": "SELECT service_name AS 服务区名称, AVG(order_sum) AS 日均订单数 FROM bss_business_day_data WHERE oper_date >= CURRENT_DATE - INTERVAL '30 days' AND delete_ts IS NULL GROUP BY service_name ORDER BY 日均订单数 DESC LIMIT 5;"
  },
  {
    "question": "今日各支付方式（微信、支付宝、现金）的总金额和订单数量分布如何？",
    "sql": "SELECT '微信' AS 支付方式, SUM(wx) AS 总金额, SUM(wx_order) AS 订单数量 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE AND delete_ts IS NULL UNION ALL SELECT '支付宝' AS 支付方式, SUM(zfb) AS 总金额, SUM(zf_order) AS 订单数量 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE AND delete_ts IS NULL UNION ALL SELECT '现金' AS 支付方式, SUM(rmb) AS 总金额, SUM(rmb_order) AS 订单数量 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE AND delete_ts IS NULL;"
  },
  {
    "question": "昨日哪个档口的现金支付订单占比最高？",
    "sql": "SELECT branch_name AS 档口名称, (rmb_order::numeric / order_sum * 100)::numeric(5,2) AS 现金订单占比 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE - INTERVAL '1 day' AND order_sum > 0 AND delete_ts IS NULL ORDER BY 现金订单占比 DESC LIMIT 1;"
  },
  {
    "question": "本月至今各服务区的总支付金额环比上月同期增长百分比是多少？",
    "sql": "WITH this_month AS (SELECT service_name, SUM(pay_sum) AS tm_sum FROM bss_business_day_data WHERE oper_date >= DATE_TRUNC('month', CURRENT_DATE) AND delete_ts IS NULL GROUP BY service_name), last_month AS (SELECT service_name, SUM(pay_sum) AS lm_sum FROM bss_business_day_data WHERE oper_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') AND oper_date < DATE_TRUNC('month', CURRENT_DATE) AND delete_ts IS NULL GROUP BY service_name) SELECT t.service_name AS 服务区名称, ROUND(((t.tm_sum - l.lm_sum) / l.lm_sum * 100), 2) AS 环比增长率 FROM this_month t JOIN last_month l ON t.service_name = l.service_name WHERE l.lm_sum > 0;"
  },
  {
    "question": "最近一周订单总数最低的服务区是哪个？",
    "sql": "SELECT service_name AS 服务区名称, SUM(order_sum) AS 总订单数 FROM bss_business_day_data WHERE oper_date >= CURRENT_DATE - INTERVAL '7 days' AND delete_ts IS NULL GROUP BY service_name ORDER BY 总订单数 ASC LIMIT 1;"
  },
  {
    "question": "昨日收入最高的服务区及其档口明细（包括各项支付金额和订单数）？",
    "sql": "SELECT service_name AS 服务区名称, branch_name AS 档口名称, wx AS 微信金额, wx_order AS 微信订单数, zfb AS 支付宝金额, zf_order AS 支付宝订单数, rmb AS 现金金额, rmb_order AS 现金订单数, pay_sum AS 总支付金额 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE - INTERVAL '1 day' AND delete_ts IS NULL ORDER BY pay_sum DESC LIMIT 1;"
  },
  {
    "question": "过去7天内每天的全网总收入趋势如何？",
    "sql": "SELECT oper_date AS 统计日期, SUM(pay_sum) AS 当日总收入 FROM bss_business_day_data WHERE oper_date >= CURRENT_DATE - INTERVAL '7 days' AND delete_ts IS NULL GROUP BY oper_date ORDER BY 统计日期;"
  },
  {
    "question": "昨日订单总数超过100的档口中，行吧支付占比最高的前3名是哪些？",
    "sql": "SELECT branch_name AS 档口名称, (xs_order::numeric / order_sum * 100)::numeric(5,2) AS 行吧支付占比 FROM bss_business_day_data WHERE oper_date = CURRENT_DATE - INTERVAL '1 day' AND order_sum > 100 AND delete_ts IS NULL ORDER BY 行吧支付占比 DESC LIMIT 3;"
  },
  {
    "question": "各服务区在2023年过境车辆总量排名前5名是哪些？",
    "sql": "SELECT sa.service_area_name AS 服务区名称, SUM(cd.customer_count) AS 过境车流量 FROM bss_car_day_count cd JOIN bss_service_area sa ON cd.service_area_id = sa.id WHERE cd.car_type = '过境' AND cd.count_date BETWEEN '2023-01-01' AND '2023-12-31' AND cd.delete_ts IS NULL AND sa.delete_ts IS NULL GROUP BY sa.service_area_name ORDER BY 过境车流量 DESC LIMIT 5;"
  },
  {
    "question": "2023年每月城际车辆总数趋势如何变化？",
    "sql": "SELECT EXTRACT(MONTH FROM count_date) AS 月份, SUM(customer_count) AS 城际车流量 FROM bss_car_day_count WHERE car_type = '城际' AND count_date BETWEEN '2023-01-01' AND '2023-12-31' AND delete_ts IS NULL GROUP BY EXTRACT(MONTH FROM count_date) ORDER BY 月份;"
  },
  {
    "question": "当前开放的服务区中，平均每日车流量最高的3个服务区是哪些？",
    "sql": "SELECT sa.service_area_name AS 服务区名称, AVG(cd.customer_count) AS 日均车流量 FROM bss_car_day_count cd JOIN bss_service_area sa ON cd.service_area_id = sa.id WHERE sa.service_state = '开放' AND cd.delete_ts IS NULL AND sa.delete_ts IS NULL GROUP BY sa.service_area_name ORDER BY 日均车流量 DESC LIMIT 3;"
  },
  {
    "question": "2023年危化品车辆占比最高的服务区是哪个？",
    "sql": "SELECT sa.service_area_name AS 服务区名称, SUM(CASE WHEN cd.car_type = '危化品' THEN cd.customer_count ELSE 0 END)::DECIMAL / SUM(cd.customer_count) AS 危化品占比 FROM bss_car_day_count cd JOIN bss_service_area sa ON cd.service_area_id = sa.id WHERE cd.count_date BETWEEN '2023-01-01' AND '2023-12-31' AND cd.delete_ts IS NULL AND sa.delete_ts IS NULL GROUP BY sa.service_area_name ORDER BY 危化品占比 DESC LIMIT 1;"
  },
  {
    "question": "近30天内各车型（过境、城际、危化品、其他）的总车流量对比情况如何？",
    "sql": "SELECT car_type AS 车辆类型, SUM(customer_count) AS 总车流量 FROM bss_car_day_count WHERE count_date >= CURRENT_DATE - 30 AND delete_ts IS NULL GROUP BY car_type ORDER BY 总车流量 DESC;"
  },
  {
    "question": "宜春分公司下属服务区2023年Q1车流量总和是多少？",
    "sql": "SELECT SUM(cd.customer_count) AS 总车流量 FROM bss_car_day_count cd JOIN bss_service_area sa ON cd.service_area_id = sa.id JOIN bss_company c ON sa.company_id = c.id WHERE c.company_name = '宜春分公司' AND cd.count_date BETWEEN '2023-01-01' AND '2023-03-31' AND cd.delete_ts IS NULL AND sa.delete_ts IS NULL AND c.delete_ts IS NULL;"
  },
  {
    "question": "最近一周每天的过境与城际车辆数量变化趋势是怎样的？",
    "sql": "SELECT count_date AS 统计日期, SUM(CASE WHEN car_type = '过境' THEN customer_count ELSE 0 END) AS 过境车流量, SUM(CASE WHEN car_type = '城际' THEN customer_count ELSE 0 END) AS 城际车流量 FROM bss_car_day_count WHERE count_date >= CURRENT_DATE - 7 AND delete_ts IS NULL GROUP BY count_date ORDER BY 统计日期;"
  },
  {
    "question": "哪些服务区在过去一个月中从未出现危化品车辆？",
    "sql": "SELECT sa.service_area_name AS 服务区名称 FROM bss_service_area sa WHERE sa.id NOT IN (SELECT DISTINCT service_area_id FROM bss_car_day_count WHERE car_type = '危化品' AND count_date >= CURRENT_DATE - 30 AND delete_ts IS NULL) AND sa.delete_ts IS NULL;"
  },
  {
    "question": "2023年单日车流量最大值出现在哪一天？对应的服务区和车流量是多少？",
    "sql": "SELECT cd.count_date AS 统计日期, sa.service_area_name AS 服务区名称, cd.customer_count AS 车流量 FROM bss_car_day_count cd JOIN bss_service_area sa ON cd.service_area_id = sa.id WHERE cd.count_date BETWEEN '2023-01-01' AND '2023-12-31' AND cd.delete_ts IS NULL AND sa.delete_ts IS NULL ORDER BY cd.customer_count DESC LIMIT 1;"
  },
  {
    "question": "每个服务区2023年各类车型的车流量分布明细（按服务区分组）？",
    "sql": "SELECT sa.service_area_name AS 服务区名称, cd.car_type AS 车辆类型, SUM(cd.customer_count) AS 车流量 FROM bss_car_day_count cd JOIN bss_service_area sa ON cd.service_area_id = sa.id WHERE cd.count_date BETWEEN '2023-01-01' AND '2023-12-31' AND cd.delete_ts IS NULL AND sa.delete_ts IS NULL GROUP BY sa.service_area_name, cd.car_type ORDER BY 服务区名称, 车流量 DESC;"
  },
  {
    "question": "各公司近30天总营收排名（万元）？",
    "sql": "SELECT c.company_name AS 公司名称, SUM(b.pay_sum) / 10000 AS 总营收_万元 FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL AND b.oper_date >= CURRENT_DATE - INTERVAL '30 days' GROUP BY c.id, c.company_name ORDER BY 总营收_万元 DESC;"
  },
  {
    "question": "各公司最近一天订单量与人均消费对比（排除无订单公司）？",
    "sql": "SELECT c.company_name AS 公司名称, SUM(b.order_sum) AS 订单总量, CASE WHEN SUM(b.order_sum) > 0 THEN ROUND(SUM(b.pay_sum) / SUM(b.order_sum), 2) ELSE 0 END AS 人均消费 FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL AND b.oper_date = (SELECT MAX(oper_date) FROM bss_business_day_data WHERE delete_ts IS NULL) GROUP BY c.id, c.company_name HAVING SUM(b.order_sum) > 0 ORDER BY 订单总量 DESC;"
  },
  {
    "question": "上月各公司现金支付占比最高的前三名？",
    "sql": "SELECT company_name AS 公司名称, ROUND(SUM(rmb) / NULLIF(SUM(pay_sum), 0) * 100, 2) AS 现金支付占比 FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL AND DATE_TRUNC('month', b.oper_date) = DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') GROUP BY c.id, c.company_name ORDER BY 现金支付占比 DESC LIMIT 3;"
  },
  {
    "question": "当前开放的服务区中，各公司平均每日营收（万元）？",
    "sql": "SELECT c.company_name AS 公司名称, AVG(daily_revenue) AS 平均日营收_万元 FROM (SELECT s.company_id, b.oper_date, SUM(b.pay_sum) / 10000 AS daily_revenue FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND s.service_state = '开放' GROUP BY s.company_id, b.oper_date) sub JOIN bss_company c ON sub.company_id = c.id WHERE c.delete_ts IS NULL GROUP BY c.id, c.company_name ORDER BY 平均日营收_万元 DESC;"
  },
  {
    "question": "本月各公司微信支付订单量环比上月变化率（%）？",
    "sql": "WITH current_month AS (SELECT c.company_name, SUM(wx_order) AS wx_orders FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL AND DATE_TRUNC('month', b.oper_date) = DATE_TRUNC('month', CURRENT_DATE) GROUP BY c.company_name), last_month AS (SELECT c.company_name, SUM(wx_order) AS wx_orders FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL AND DATE_TRUNC('month', b.oper_date) = DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') GROUP BY c.company_name) SELECT cm.company_name AS 公司名称, ROUND((cm.wx_orders - COALESCE(lm.wx_orders, 0)) * 100.0 / NULLIF(lm.wx_orders, 0), 2) AS 微信订单环比变化率 FROM current_month cm LEFT JOIN last_month lm ON cm.company_name = lm.company_name ORDER BY 微信订单环比变化率 DESC;"
  },
  {
    "question": "各公司订单总量前五的服务区明细（公司+服务区+订单量）？",
    "sql": "SELECT c.company_name AS 公司名称, b.service_name AS 服务区名称, SUM(b.order_sum) AS 订单总量 FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL GROUP BY c.id, c.company_name, b.service_name ORDER BY 订单总量 DESC LIMIT 5;"
  },
  {
    "question": "各公司最近7天日均订单量与历史日均订单量对比（%）？",
    "sql": "WITH recent AS (SELECT s.company_id, AVG(b.order_sum) AS avg_orders FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND b.oper_date >= CURRENT_DATE - 7 GROUP BY s.company_id), historical AS (SELECT s.company_id, AVG(b.order_sum) AS avg_orders FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL GROUP BY s.company_id) SELECT c.company_name AS 公司名称, ROUND((r.avg_orders - h.avg_orders) * 100.0 / NULLIF(h.avg_orders, 0), 2) AS 近七天相对历史变化率 FROM recent r JOIN historical h ON r.company_id = h.company_id JOIN bss_company c ON r.company_id = c.id WHERE c.delete_ts IS NULL ORDER BY 近七天相对历史变化率 DESC;"
  },
  {
    "question": "各公司支付宝支付金额占总支付金额比例超过10%的公司列表？",
    "sql": "SELECT c.company_name AS 公司名称, ROUND(SUM(b.zfb) / SUM(b.pay_sum) * 100, 2) AS 支付宝占比 FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL GROUP BY c.id, c.company_name HAVING SUM(b.pay_sum) > 0 AND SUM(b.zfb) / SUM(b.pay_sum) > 0.1 ORDER BY 支付宝占比 DESC;"
  },
  {
    "question": "各公司最近一个月无营收记录的服务区数量？",
    "sql": "SELECT c.company_name AS 公司名称, COUNT(DISTINCT s.service_area_no) AS 零营收服务区数 FROM bss_service_area s JOIN bss_company c ON s.company_id = c.id LEFT JOIN bss_business_day_data b ON s.service_area_no = b.service_no AND b.oper_date >= CURRENT_DATE - INTERVAL '1 month' AND b.delete_ts IS NULL WHERE s.delete_ts IS NULL AND c.delete_ts IS NULL AND b.id IS NULL GROUP BY c.id, c.company_name ORDER BY 零营收服务区数 DESC;"
  },
  {
    "question": "各公司订单量最高的单日数据（公司+日期+订单量）？",
    "sql": "SELECT company_name AS 公司名称, oper_date AS 日期, max_orders AS 最高单日订单量 FROM (SELECT c.company_name, b.oper_date, SUM(b.order_sum) AS max_orders, ROW_NUMBER() OVER (PARTITION BY c.id ORDER BY SUM(b.order_sum) DESC) AS rn FROM bss_business_day_data b JOIN bss_service_area s ON b.service_no = s.service_area_no JOIN bss_company c ON s.company_id = c.id WHERE b.delete_ts IS NULL AND s.delete_ts IS NULL AND c.delete_ts IS NULL GROUP BY c.id, c.company_name, b.oper_date) sub WHERE rn = 1 ORDER BY 最高单日订单量 DESC;"
  },
  {
    "question": "各路段下辖服务区的平均车流量是多少？按车流量从高到低排序。",
    "sql": "SELECT sr.section_name AS 路段名称, AVG(cd.customer_count) AS 平均车流量 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_car_day_count cd ON link.service_area_id = cd.service_area_id WHERE sr.delete_ts IS NULL AND cd.delete_ts IS NULL GROUP BY sr.section_name ORDER BY 平均车流量 DESC;"
  },
  {
    "question": "每条路线中单位车流转化收入最高的服务区是哪个？（仅统计开放状态的服务区）",
    "sql": "SELECT t.route_name AS 路线名称, t.service_name AS 服务区名称, t.unit_income AS 单位车流转化收入 FROM (SELECT sr.route_name, sa.service_area_name AS service_name, SUM(bd.pay_sum) / NULLIF(SUM(cd.customer_count), 0) AS unit_income, ROW_NUMBER() OVER (PARTITION BY sr.route_name ORDER BY SUM(bd.pay_sum) / NULLIF(SUM(cd.customer_count), 0) DESC) AS rn FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_service_area sa ON link.service_area_id = sa.id JOIN bss_car_day_count cd ON sa.id = cd.service_area_id JOIN bss_business_day_data bd ON sa.service_area_no = bd.service_no WHERE sr.delete_ts IS NULL AND sa.delete_ts IS NULL AND cd.delete_ts IS NULL AND bd.delete_ts IS NULL AND sa.service_state = '开放' GROUP BY sr.route_name, sa.service_area_name) t WHERE t.rn = 1;"
  },
  {
    "question": "近30天内哪些路段的综合活跃度（车流+消费）最高？取前5名。",
    "sql": "SELECT sr.section_name AS 路段名称, SUM(cd.customer_count) AS 总车流量, SUM(bd.pay_sum) AS 总收入, (SUM(cd.customer_count) + SUM(bd.pay_sum)) AS 综合活跃度 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_car_day_count cd ON link.service_area_id = cd.service_area_id JOIN bss_business_day_data bd ON cd.count_date = bd.oper_date JOIN bss_service_area sa ON link.service_area_id = sa.id WHERE sr.delete_ts IS NULL AND cd.delete_ts IS NULL AND bd.delete_ts IS NULL AND sa.delete_ts IS NULL AND cd.count_date >= CURRENT_DATE - 30 AND bd.oper_date >= CURRENT_DATE - 30 GROUP BY sr.section_name ORDER BY 综合活跃度 DESC LIMIT 5;"
  },
  {
    "question": "昌栗路段下辖各服务区的日均车流量和日均收入对比如何？",
    "sql": "SELECT sa.service_area_name AS 服务区名称, AVG(cd.customer_count) AS 日均车流量, AVG(bd.pay_sum) AS 日均收入 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_service_area sa ON link.service_area_id = sa.id JOIN bss_car_day_count cd ON sa.id = cd.service_area_id JOIN bss_business_day_data bd ON sa.service_area_no = bd.service_no WHERE sr.delete_ts IS NULL AND sa.delete_ts IS NULL AND cd.delete_ts IS NULL AND bd.delete_ts IS NULL AND sr.section_name = '昌栗' GROUP BY sa.service_area_name;"
  },
  {
    "question": "不同车辆类型的车流量分布情况如何？按路段分类统计。",
    "sql": "SELECT sr.section_name AS 路段名称, cd.car_type AS 车辆类型, SUM(cd.customer_count) AS 总车流量 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_car_day_count cd ON link.service_area_id = cd.service_area_id WHERE sr.delete_ts IS NULL AND cd.delete_ts IS NULL AND sr.section_name IS NOT NULL GROUP BY sr.section_name, cd.car_type ORDER BY 路段名称, 总车流量 DESC;"
  },
  {
    "question": "哪些服务区的单位车流转化收入低于整体平均水平？列出具体数值。",
    "sql": "WITH overall_avg AS (SELECT AVG(unit_income) AS avg_unit_income FROM (SELECT SUM(bd.pay_sum) / NULLIF(SUM(cd.customer_count), 0) AS unit_income FROM bss_car_day_count cd JOIN bss_business_day_data bd ON cd.count_date = bd.oper_date JOIN bss_service_area sa ON cd.service_area_id = sa.id JOIN bss_service_area_mapper sm ON sa.id = sm.service_area_id WHERE cd.delete_ts IS NULL AND bd.delete_ts IS NULL AND sa.delete_ts IS NULL AND sm.delete_ts IS NULL GROUP BY sa.service_area_name) sub) SELECT sa.service_area_name AS 服务区名称, SUM(bd.pay_sum) / NULLIF(SUM(cd.customer_count), 0) AS 单位车流转化收入 FROM bss_car_day_count cd JOIN bss_business_day_data bd ON cd.count_date = bd.oper_date JOIN bss_service_area sa ON cd.service_area_id = sa.id JOIN bss_service_area_mapper sm ON sa.id = sm.service_area_id WHERE cd.delete_ts IS NULL AND bd.delete_ts IS NULL AND sa.delete_ts IS NULL AND sm.delete_ts IS NULL GROUP BY sa.service_area_name HAVING SUM(bd.pay_sum) / NULLIF(SUM(cd.customer_count), 0) < (SELECT avg_unit_income FROM overall_avg);"
  },
  {
    "question": "昌宁路段下辖服务区中，订单总数排名前三的档口是哪些？",
    "sql": "SELECT bd.branch_name AS 档口名称, SUM(bd.order_sum) AS 订单总数 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_service_area sa ON link.service_area_id = sa.id JOIN bss_business_day_data bd ON sa.service_area_no = bd.service_no WHERE sr.delete_ts IS NULL AND sa.delete_ts IS NULL AND bd.delete_ts IS NULL AND sr.section_name = '昌宁' GROUP BY bd.branch_name ORDER BY 订单总数 DESC LIMIT 3;"
  },
  {
    "question": "最近一周内，各路段的日均车流量波动幅度（标准差）是多少？",
    "sql": "SELECT sr.section_name AS 路段名称, STDDEV(cd.customer_count) AS 车流量标准差 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_car_day_count cd ON link.service_area_id = cd.service_area_id WHERE sr.delete_ts IS NULL AND cd.delete_ts IS NULL AND cd.count_date >= CURRENT_DATE - 7 GROUP BY sr.section_name ORDER BY 车流量标准差 DESC;"
  },
  {
    "question": "哪些路段存在服务区处于关闭状态？列出这些路段及其关闭的服务区数量。",
    "sql": "SELECT sr.section_name AS 路段名称, COUNT(sa.id) AS 关闭服务区数量 FROM bss_section_route sr JOIN bss_section_route_area_link link ON sr.id = link.section_route_id JOIN bss_service_area sa ON link.service_area_id = sa.id WHERE sr.delete_ts IS NULL AND sa.delete_ts IS NULL AND sa.service_state = '关闭' GROUP BY sr.section_name HAVING COUNT(sa.id) > 0;"
  },
  {
    "question": "不同数据来源系统（如驿购、驿美）每日记录数分布情况如何？",
    "sql": "SELECT source_system_type AS 数据来源系统, oper_date AS 统计日期, COUNT(*) AS 记录数 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL GROUP BY source_system_type, oper_date ORDER BY 统计日期 DESC, 记录数 DESC;"
  },
  {
    "question": "各数据来源系统的平均每日更新频率（记录数/天）是多少？",
    "sql": "SELECT source_system_type AS 数据来源系统, COUNT(*)::float / COUNT(DISTINCT oper_date) AS 平均每日记录数 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL GROUP BY source_system_type ORDER BY 平均每日记录数 DESC;"
  },
  {
    "question": "哪些服务区在所有数据来源系统中均有覆盖？即来源系统覆盖率100%的服务区",
    "sql": "SELECT t.service_name AS 服务区名称 FROM (SELECT m.service_name, COUNT(DISTINCT m.source_system_type) AS 系统数量 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL GROUP BY m.service_name) t WHERE 系统数量 = (SELECT COUNT(DISTINCT source_system_type) FROM bss_service_area_mapper WHERE delete_ts IS NULL);"
  },
  {
    "question": "最近7天内，哪个数据来源系统新增记录最多？",
    "sql": "SELECT source_system_type AS 数据来源系统, COUNT(*) AS 新增记录数 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL AND oper_date >= CURRENT_DATE - 7 GROUP BY source_system_type ORDER BY 新增记录数 DESC LIMIT 1;"
  },
  {
    "question": "各数据来源系统的订单总数和总支付金额对比如何？",
    "sql": "SELECT source_system_type AS 数据来源系统, SUM(order_sum) AS 总订单数, SUM(pay_sum) AS 总支付金额 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL GROUP BY source_system_type ORDER BY 总支付金额 DESC;"
  },
  {
    "question": "过去30天内，数据来源系统为'驿购'的日均记录数变化趋势是怎样的？",
    "sql": "SELECT oper_date AS 统计日期, COUNT(*) AS 日记录数 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL AND source_system_type = '驿购' AND oper_date >= CURRENT_DATE - 30 GROUP BY oper_date ORDER BY 统计日期;"
  },
  {
    "question": "数据来源系统中，哪个系统的记录缺失率最高（即未填充值字段比例）？",
    "sql": "SELECT source_system_type AS 数据来源系统, AVG(CASE WHEN wx IS NULL THEN 1 ELSE 0 END) AS 微信缺失率, AVG(CASE WHEN zfb IS NULL THEN 1 ELSE 0 END) AS 支付宝缺失率 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL GROUP BY source_system_type ORDER BY 微信缺失率 DESC LIMIT 1;"
  },
  {
    "question": "不同数据来源系统的更新活跃度（最近30天有数据的天数占比）如何？",
    "sql": "SELECT source_system_type AS 数据来源系统, COUNT(DISTINCT oper_date)::float / 30 AS 活跃度 FROM bss_business_day_data b JOIN bss_service_area_mapper m ON b.service_no = m.service_no WHERE b.delete_ts IS NULL AND m.delete_ts IS NULL AND oper_date >= CURRENT_DATE - 30 GROUP BY source_system_type ORDER BY 活跃度 DESC;"
  }
]