[
  {
    "question": "统计最近7天各服务区每日总营收金额，并按日期和服务区名称排序。",
    "sql": "SELECT oper_date AS 统计日期, service_name AS 服务区名称, SUM(pay_sum) AS 总营收金额 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date >= CURRENT_DATE - 7 GROUP BY oper_date, service_name ORDER BY oper_date DESC, 总营收金额 DESC;"
  },
  {
    "question": "查询2023年4月1日各档口的订单总数和总营收金额，并按总营收金额降序排序。",
    "sql": "SELECT branch_name AS 档口名称, order_sum AS 订单总数, pay_sum AS 总营收金额 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' ORDER BY 总营收金额 DESC;"
  },
  {
    "question": "分析2023年各月份各服务区的平均每日营收金额，并按月份和服务区名称排序。",
    "sql": "SELECT DATE_TRUNC('month', oper_date) AS 月份, service_name AS 服务区名称, AVG(pay_sum) AS 平均每日营收金额 FROM bss_business_day_data WHERE delete_ts IS NULL AND EXTRACT(YEAR FROM oper_date) = 2023 GROUP BY DATE_TRUNC('month', oper_date), service_name ORDER BY 月份, 平均每日营收金额 DESC;"
  },
  {
    "question": "找出2023年4月1日订单总数排名前5的服务区。",
    "sql": "SELECT service_name AS 服务区名称, SUM(order_sum) AS 总订单数 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' GROUP BY service_name ORDER BY 总订单数 DESC LIMIT 5;"
  },
  {
    "question": "统计2023年4月1日各支付方式的总支付金额和总订单数。",
    "sql": "SELECT '微信' AS 支付方式, SUM(wx) AS 总支付金额, SUM(wx_order) AS 总订单数 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' UNION ALL SELECT '支付宝', SUM(zfb), SUM(zf_order) FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' UNION ALL SELECT '现金', SUM(rmb), SUM(rmb_order) FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' UNION ALL SELECT '行吧', SUM(xs), SUM(xs_order) FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' UNION ALL SELECT '金豆', SUM(jd), SUM(jd_order) FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01';"
  },
  {
    "question": "查询2023年4月1日各服务区各档口的营收明细。",
    "sql": "SELECT service_name AS 服务区名称, branch_name AS 档口名称, pay_sum AS 营收金额 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' ORDER BY 服务区名称, 营收金额 DESC;"
  },
  {
    "question": "计算2023年各月各支付方式的总支付金额，按月份和支付方式排序。",
    "sql": "SELECT DATE_TRUNC('month', oper_date) AS 月份, '微信' AS 支付方式, SUM(wx) AS 总支付金额 FROM bss_business_day_data WHERE delete_ts IS NULL AND EXTRACT(YEAR FROM oper_date) = 2023 GROUP BY DATE_TRUNC('month', oper_date) UNION ALL SELECT DATE_TRUNC('month', oper_date), '支付宝', SUM(zfb) FROM bss_business_day_data WHERE delete_ts IS NULL AND EXTRACT(YEAR FROM oper_date) = 2023 GROUP BY DATE_TRUNC('month', oper_date) UNION ALL SELECT DATE_TRUNC('month', oper_date), '现金', SUM(rmb) FROM bss_business_day_data WHERE delete_ts IS NULL AND EXTRACT(YEAR FROM oper_date) = 2023 GROUP BY DATE_TRUNC('month', oper_date) UNION ALL SELECT DATE_TRUNC('month', oper_date), '行吧', SUM(xs) FROM bss_business_day_data WHERE delete_ts IS NULL AND EXTRACT(YEAR FROM oper_date) = 2023 GROUP BY DATE_TRUNC('month', oper_date) UNION ALL SELECT DATE_TRUNC('month', oper_date), '金豆', SUM(jd) FROM bss_business_day_data WHERE delete_ts IS NULL AND EXTRACT(YEAR FROM oper_date) = 2023 GROUP BY DATE_TRUNC('month', oper_date) ORDER BY 月份, 支付方式;"
  },
  {
    "question": "找出2023年4月1日微信支付订单数量超过100的档口信息。",
    "sql": "SELECT branch_name AS 档口名称, wx_order AS 微信订单数 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' AND wx_order > 100 ORDER BY 微信订单数 DESC;"
  },
  {
    "question": "统计2023年4月1日各服务区的现金支付金额占总营收金额的比例。",
    "sql": "SELECT service_name AS 服务区名称, SUM(rmb) / SUM(pay_sum) * 100 AS 现金支付占比 FROM bss_business_day_data WHERE delete_ts IS NULL AND oper_date = '2023-04-01' GROUP BY service_name ORDER BY 现金支付占比 DESC;"
  },
  {
    "question": "查询2023年4月1日所有关闭状态的服务区营收数据。",
    "sql": "SELECT bbd.service_name AS 服务区名称, bbd.oper_date AS 统计日期, bbd.pay_sum AS 总营收金额 FROM bss_business_day_data bbd JOIN bss_service_area sa ON bbd.service_no = sa.service_area_no WHERE sa.service_state = '关闭' AND bbd.oper_date = '2023-04-01' AND bbd.delete_ts IS NULL;"
  },
  {
    "question": "统计最近7天各服务区的总车流量，并按车流量降序排列。",
    "sql": "SELECT service_area_id AS 服务区ID, SUM(customer_count) AS 总车流量 FROM bss_car_day_count WHERE count_date >= CURRENT_DATE - 7 AND delete_ts IS NULL GROUP BY service_area_id ORDER BY 总车流量 DESC;"
  },
  {
    "question": "查询2023年4月1日各车辆类别在各服务区的数量分布。",
    "sql": "SELECT service_area_id AS 服务区ID, car_type AS 车辆类别, customer_count AS 车辆数量 FROM bss_car_day_count WHERE count_date = '2022-03-02' AND delete_ts IS NULL;"
  },
  {
    "question": "找出2023年3月车流量最高的5个服务区。",
    "sql": "SELECT service_area_id AS 服务区ID, SUM(customer_count) AS 总车流量 FROM bss_car_day_count WHERE count_date BETWEEN '2022-03-01' AND '2022-03-31' AND delete_ts IS NULL GROUP BY service_area_id ORDER BY 总车流量 DESC LIMIT 5;"
  },
  {
    "question": "计算各车辆类别在所有服务区的占比。",
    "sql": "SELECT car_type AS 车辆类别, SUM(customer_count) * 100.0 / (SELECT SUM(customer_count) FROM bss_car_day_count WHERE delete_ts IS NULL) AS 占比百分比 FROM bss_car_day_count WHERE delete_ts IS NULL GROUP BY car_type;"
  },
  {
    "question": "分析2023年各季度各服务区的平均每日车流量。",
    "sql": "SELECT service_area_id AS 服务区ID, EXTRACT(QUARTER FROM count_date) AS 季度, AVG(customer_count) AS 日均车流量 FROM bss_car_day_count WHERE EXTRACT(YEAR FROM count_date) = 2023 AND delete_ts IS NULL GROUP BY service_area_id, 季度 ORDER BY 季度, 日均车流量 DESC;"
  },
  {
    "question": "查询2023年1月1日至2023年1月7日每天的总车流量趋势。",
    "sql": "SELECT count_date AS 统计日期, SUM(customer_count) AS 总车流量 FROM bss_car_day_count WHERE count_date BETWEEN '2022-03-01' AND '2022-03-07' AND delete_ts IS NULL GROUP BY count_date ORDER BY count_date;"
  },
  {
    "question": "列出2023年车流量最低的10个服务区。",
    "sql": "SELECT service_area_id AS 服务区ID, SUM(customer_count) AS 总车流量 FROM bss_car_day_count WHERE EXTRACT(YEAR FROM count_date) = 2023 AND delete_ts IS NULL GROUP BY service_area_id ORDER BY 总车流量 ASC LIMIT 10;"
  },
  {
    "question": "查找2023年3月15日车流量超过1000的车辆类别及其数量。",
    "sql": "SELECT car_type AS 车辆类别, customer_count AS 车辆数量 FROM bss_car_day_count WHERE count_date = '2022-03-15' AND customer_count > 1000 AND delete_ts IS NULL;"
  },
  {
    "question": "统计2023年各月各服务区的车流量并按月份排序。",
    "sql": "SELECT service_area_id AS 服务区ID, EXTRACT(MONTH FROM count_date) AS 月份, SUM(customer_count) AS 总车流量 FROM bss_car_day_count WHERE EXTRACT(YEAR FROM count_date) = 2023 AND delete_ts IS NULL GROUP BY service_area_id, 月份 ORDER BY 月份;"
  },
  {
    "question": "找出2023年3月车流量增长最快的三个服务区。",
    "sql": "WITH daily_counts AS (SELECT service_area_id, count_date, SUM(customer_count) AS daily_count FROM bss_car_day_count WHERE EXTRACT(YEAR FROM count_date) = 2023 AND EXTRACT(MONTH FROM count_date) IN (3, 2) AND delete_ts IS NULL GROUP BY service_area_id, count_date), monthly_avg AS (SELECT service_area_id, EXTRACT(MONTH FROM count_date) AS 月份, AVG(daily_count) AS avg_count FROM daily_counts GROUP BY service_area_id, 月份) SELECT m1.service_area_id AS 服务区ID, m2.avg_count - m1.avg_count AS 增长量 FROM monthly_avg m1 JOIN monthly_avg m2 ON m1.service_area_id = m2.service_area_id AND m1.月份 = 2 AND m2.月份 = 3 ORDER BY 增长量 DESC LIMIT 3;"
  },
  {
    "question": "统计各公司管辖的服务区数量，并按数量降序排列。",
    "sql": "SELECT b.company_name AS 公司名称, COUNT(a.id) AS 服务区数量 FROM bss_service_area a JOIN bss_company b ON a.company_id = b.id WHERE a.delete_ts IS NULL AND b.delete_ts IS NULL GROUP BY b.company_name ORDER BY 服务区数量 DESC;"
  },
  {
    "question": "计算2023年4月1日各公司管辖服务区的总营收金额，并按营收降序排列。",
    "sql": "SELECT c.company_name AS 公司名称, SUM(d.pay_sum) AS 总营收 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date = '2023-04-01' GROUP BY c.company_name ORDER BY 总营收 DESC;"
  },
  {
    "question": "查询2023年4月各公司管辖服务区的平均营收，并按平均营收从高到低排序。",
    "sql": "SELECT c.company_name AS 公司名称, AVG(d.pay_sum) AS 平均营收 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 平均营收 DESC;"
  },
  {
    "question": "找出2023年4月总营收排名前五的公司及其管辖的服务区数量。",
    "sql": "SELECT c.company_name AS 公司名称, COUNT(a.id) AS 服务区数量, SUM(d.pay_sum) AS 总营收 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 总营收 DESC LIMIT 5;"
  },
  {
    "question": "查询2023年4月各公司管辖服务区的现金支付总金额，并按金额降序排列。",
    "sql": "SELECT c.company_name AS 公司名称, SUM(d.rmb) AS 现金支付总额 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 现金支付总额 DESC;"
  },
  {
    "question": "比较2023年4月各公司管辖服务区的微信支付与支付宝支付金额，并按总支付金额排序。",
    "sql": "SELECT c.company_name AS 公司名称, SUM(d.wx) AS 微信支付总额, SUM(d.zfb) AS 支付宝支付总额, SUM(d.wx + d.zfb) AS 总支付金额 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 总支付金额 DESC;"
  },
  {
    "question": "查询2023年4月各公司管辖服务区的订单总数，并按订单数从高到低排序。",
    "sql": "SELECT c.company_name AS 公司名称, SUM(d.order_sum) AS 订单总数 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 订单总数 DESC;"
  },
  {
    "question": "找出2023年4月平均营收最低的三个公司及其管辖的服务区平均营收。",
    "sql": "SELECT c.company_name AS 公司名称, AVG(d.pay_sum) AS 平均营收 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 平均营收 ASC LIMIT 3;"
  },
  {
    "question": "统计2023年4月各公司管辖服务区的每日平均营收，并按公司名称排序。",
    "sql": "SELECT c.company_name AS 公司名称, AVG(d.pay_sum) AS 日均营收 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 公司名称;"
  },
  {
    "question": "查询2023年4月各公司管辖服务区的营收总额及服务区数量，并按营收占比（营收总额除以服务区数量）排序。",
    "sql": "SELECT c.company_name AS 公司名称, SUM(d.pay_sum) AS 总营收, COUNT(a.id) AS 服务区数量, SUM(d.pay_sum) / COUNT(a.id) AS 营收占比 FROM bss_service_area a JOIN bss_company c ON a.company_id = c.id JOIN bss_business_day_data d ON a.service_area_no = d.service_no WHERE d.oper_date BETWEEN '2023-04-01' AND '2023-04-30' GROUP BY c.company_name ORDER BY 营收占比 DESC;"
  },
  {
    "question": "统计每个路段关联的服务区数量，并按数量降序排列。",
    "sql": "SELECT bsr.section_name AS 路段名称, COUNT(bsral.service_area_id) AS 服务区数量 FROM bss_section_route bsr LEFT JOIN bss_section_route_area_link bsral ON bsr.id = bsral.section_route_id WHERE bsr.delete_ts IS NULL GROUP BY bsr.section_name ORDER BY 服务区数量 DESC;"
  },
  {
    "question": "列出没有关联任何服务区的路段名称。",
    "sql": "SELECT bsr.section_name AS 路段名称 FROM bss_section_route bsr LEFT JOIN bss_section_route_area_link bsral ON bsr.id = bsral.section_route_id WHERE bsral.section_route_id IS NULL AND bsr.delete_ts IS NULL;"
  },
  {
    "question": "统计每个路线关联的服务区数量，并按路线名称分组。",
    "sql": "SELECT bsr.route_name AS 路线名称, COUNT(bsral.service_area_id) AS 服务区数量 FROM bss_section_route bsr LEFT JOIN bss_section_route_area_link bsral ON bsr.id = bsral.section_route_id WHERE bsr.delete_ts IS NULL GROUP BY bsr.route_name;"
  },
  {
    "question": "列出所有服务区及其所属路线名称，按服务区名称排序。",
    "sql": "SELECT sa.service_area_name AS 服务区名称, sr.route_name AS 路线名称 FROM bss_service_area sa LEFT JOIN bss_section_route_area_link sral ON sa.id = sral.service_area_id LEFT JOIN bss_section_route sr ON sral.section_route_id = sr.id WHERE sa.delete_ts IS NULL ORDER BY 服务区名称;"
  },
  {
    "question": "统计每个路段的覆盖率，即关联服务区数量占总服务区数量的比例。",
    "sql": "WITH total_areas AS (SELECT COUNT(*) AS 总服务区数 FROM bss_service_area WHERE delete_ts IS NULL), section_areas AS (SELECT bsr.section_name AS 路段名称, COUNT(bsral.service_area_id) AS 服务区数量 FROM bss_section_route bsr LEFT JOIN bss_section_route_area_link bsral ON bsr.id = bsral.section_route_id WHERE bsr.delete_ts IS NULL GROUP BY bsr.section_name) SELECT 路段名称, 服务区数量 / (SELECT 总服务区数 FROM total_areas)::numeric AS 覆盖率 FROM section_areas;"
  },
  {
    "question": "查找关联服务区数量最多的前5个路段。",
    "sql": "SELECT bsr.section_name AS 路段名称, COUNT(bsral.service_area_id) AS 服务区数量 FROM bss_section_route bsr LEFT JOIN bss_section_route_area_link bsral ON bsr.id = bsral.section_route_id WHERE bsr.delete_ts IS NULL GROUP BY bsr.section_name ORDER BY 服务区数量 DESC LIMIT 5;"
  },
  {
    "question": "查询特定路段（例如路段名称为'昌九'）关联的所有服务区名称。",
    "sql": "SELECT sa.service_area_name AS 服务区名称 FROM bss_service_area sa INNER JOIN bss_section_route_area_link sral ON sa.id = sral.service_area_id INNER JOIN bss_section_route sr ON sral.section_route_id = sr.id WHERE sr.section_name = '昌九' AND sa.delete_ts IS NULL;"
  },
  {
    "question": "统计每条路线关联的路段数量，并按路线名称排序。",
    "sql": "SELECT route_name AS 路线名称, COUNT(*) AS 路段数量 FROM bss_section_route WHERE delete_ts IS NULL GROUP BY route_name ORDER BY 路线名称;"
  },
  {
    "question": "找出关联路段最多的路线名称及关联的路段数量。",
    "sql": "SELECT route_name AS 路线名称, COUNT(*) AS 路段数量 FROM bss_section_route WHERE delete_ts IS NULL GROUP BY route_name ORDER BY 路段数量 DESC LIMIT 1;"
  },
  {
    "question": "列出所有路段及其关联的服务区数量，筛选出关联数量大于等于2的路段。",
    "sql": "SELECT bsr.section_name AS 路段名称, COUNT(bsral.service_area_id) AS 服务区数量 FROM bss_section_route bsr LEFT JOIN bss_section_route_area_link bsral ON bsr.id = bsral.section_route_id WHERE bsr.delete_ts IS NULL GROUP BY bsr.section_name HAVING COUNT(bsral.service_area_id) >= 2;"
  },
  {
    "question": "统计当前所有开放状态的服务区数量及占比。",
    "sql": "SELECT COUNT(*) AS 开放服务区数量, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM bss_service_area WHERE delete_ts IS NULL), 2) AS 开放率百分比 FROM bss_service_area WHERE service_state = '开放' AND delete_ts IS NULL;"
  },
  {
    "question": "列出所有关闭状态的服务区名称及其所属公司。",
    "sql": "SELECT sa.service_area_name AS 服务区名称, c.company_name AS 所属公司 FROM bss_service_area sa LEFT JOIN bss_company c ON sa.company_id = c.id WHERE sa.service_state = '关闭' AND sa.delete_ts IS NULL;"
  },
  {
    "question": "按公司统计各公司管理的服务区数量及开放率。",
    "sql": "SELECT c.company_name AS 所属公司, COUNT(sa.id) AS 服务区总数, ROUND(SUM(CASE WHEN sa.service_state = '开放' THEN 1 ELSE 0 END) * 100.0 / COUNT(sa.id), 2) AS 开放率 FROM bss_service_area sa LEFT JOIN bss_company c ON sa.company_id = c.id WHERE sa.delete_ts IS NULL GROUP BY c.company_name;"
  },
  {
    "question": "按服务区类型统计信息化与智能化服务区的数量及占比。",
    "sql": "SELECT service_area_type AS 服务区类型, COUNT(*) AS 数量, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM bss_service_area WHERE delete_ts IS NULL), 2) AS 占比百分比 FROM bss_service_area WHERE delete_ts IS NULL GROUP BY service_area_type;"
  },
  {
    "question": "查询经纬度位于东经115度以东的服务区列表。",
    "sql": "SELECT service_area_name AS 服务区名称, service_position AS 经纬度 FROM bss_service_area WHERE CAST(SPLIT_PART(service_position, ',', 1) AS NUMERIC) > 115 AND delete_ts IS NULL;"
  },
  {
    "question": "列出最近一周内创建的服务区明细。",
    "sql": "SELECT service_area_name AS 服务区名称, create_ts AS 创建时间 FROM bss_service_area WHERE create_ts >= NOW() - INTERVAL '7 days' AND delete_ts IS NULL;"
  },
  {
    "question": "统计各公司管理的服务区中，开放状态服务区数量排名前五的公司。",
    "sql": "SELECT c.company_name AS 所属公司, COUNT(sa.id) AS 开放服务区数量 FROM bss_service_area sa LEFT JOIN bss_company c ON sa.company_id = c.id WHERE sa.service_state = '开放' AND sa.delete_ts IS NULL GROUP BY c.company_name ORDER BY 开放服务区数量 DESC LIMIT 5;"
  },
  {
    "question": "查询没有关联任何路段路线的服务区列表。",
    "sql": "SELECT sa.service_area_name AS 服务区名称 FROM bss_service_area sa LEFT JOIN bss_section_route_area_link link ON sa.id = link.service_area_id WHERE link.section_route_id IS NULL AND sa.delete_ts IS NULL;"
  },
  {
    "question": "统计每个服务区类型中处于关闭状态的服务区数量。",
    "sql": "SELECT service_area_type AS 服务区类型, COUNT(*) AS 关闭数量 FROM bss_service_area WHERE service_state = '关闭' AND delete_ts IS NULL GROUP BY service_area_type;"
  },
  {
    "question": "列出所有服务区及其所属公司信息，按公司名称排序。",
    "sql": "SELECT sa.service_area_name AS 服务区名称, c.company_name AS 所属公司 FROM bss_service_area sa LEFT JOIN bss_company c ON sa.company_id = c.id WHERE sa.delete_ts IS NULL ORDER BY c.company_name;"
  }
]