You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求帮助:将Cloudflare SQL查询转换为GraphQL查询

Cloudflare GraphQL 查询转换结果

以下是对应你提供的SQL的Cloudflare Analytics GraphQL查询:

query MonthlyAccountZoneMetrics {
  viewer {
    # 过滤指定账户ID(对应SQL中m.user_id IN (...))
    accounts(filter: { accountTag_in: ["123123", "321321"] }) {
      account_id: accountTag
      account_name: name
      # 过滤指定套餐的Zone(对应SQL中zone_plan = 'XYZ')
      zones(filter: { plan: { name: "XYZ" } }) {
        zone_name: name
        zone_rate_plan: plan {
          name
        }
        # 月度请求数据分组(对应SQL的requests_monthly表)
        httpRequests1MonthGroups(
          # 日期范围过滤(对应SQL中month_end_date BETWEEN ...)
          filter: {
            date_geq: "2023-01-01"
            date_leq: "2023-07-31"
          }
          limit: 1000
          orderBy: [date_ASC]
        ) {
          month_end_date: date
          sum {
            monthly_cached_requests: cachedRequests
            monthly_requests: requests
            monthly_data_transfer_bytes: bytes
          }
        }
      }
    }
  }
}

说明

  1. Cloudflare GraphQL API不支持在查询内直接进行算术运算,因此以下计算需要在客户端完成:
    • monthly_uncached_requests = monthly_requests - monthly_cached_requests
    • monthly_data_transfer_gb = monthly_data_transfer_bytes / 1e9
  2. 字段映射:
    • SQL中的user_id对应GraphQL的accountTag
    • SQL中的zoneid对应GraphQL的zoneTag(若需要可在zones字段下添加该字段)
    • 月度聚合数据来自httpRequests1MonthGroups,按日期自动分组,无需手动指定GROUP BY
  3. 若需要调整数据量,可修改limit参数;若需其他维度的聚合,可添加对应字段到查询中。

内容的提问来源于stack exchange,提问作者Ashish Panwar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 02:38:16