使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对结果排序
您可以使用 ORDER BY
子句指定响应中的行顺序,该子句由一个或多个以英文逗号分隔的以下序列组成:
FieldName ('ASC' | 'DESC')?
如果您没有在字段名称的后面指定 ASC
或 DESC
,那么 Google Ads API 将默认使用 ASC
。
以下 ORDER BY
子句会按展示次数的降序和广告系列名称的升序对广告系列一级的报告进行排序:
ORDER BY metrics.impressions DESC, campaign.name ASC
不允许按以下内容进行排序:
- 未选定资源的属性
- 未选定的指标
- 未选定的细分
- 以下类型的字段:
限制结果数量
您可以使用 LIMIT
子句限制返回的结果总数。将此结果与排序的结果相结合,您可以生成“前 N 个”报告,例如包含过去 30 天内展示次数最高的五个广告系列的报告:
SELECT
campaign.id,
campaign.name,
metrics.impressions
FROM campaign
WHERE segments.date DURING LAST_30_DAYS
ORDER BY metrics.impressions DESC
LIMIT 5
不允许对以下内容进行过滤:
- 未选定的细分,但“核心”日期细分字段除外。
- 核心日期细分字段包括
segments.date
、segments.week
、segments.month
、segments.quarter
和 segments.year
。
- 任何消息类型的字段,但 Int64Value、StringValue 等基元除外。
- 任何消息类型的重复字段的属性,但 Int64Value、StringValue 等基元除外。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eYou can control the order of results using the \u003ccode\u003eORDER BY\u003c/code\u003e clause, specifying fields and sort direction (ASC or DESC).\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eLIMIT\u003c/code\u003e clause lets you restrict the number of returned results, enabling "top N" reports when combined with \u003ccode\u003eORDER BY\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eOrdering is disallowed by attributes of non-selected resources, by non-selected metrics or segments, and for fields of type \u003ccode\u003eMESSAGE\u003c/code\u003e, repeated fields, or attributes of repeated fields.\u003c/p\u003e\n"],["\u003cp\u003eFiltering is restricted for segments without selection (excluding core date segments), fields of non-primitive message types, and attributes of repeated fields with non-primitive message types.\u003c/p\u003e\n"]]],[],null,["Order results\n-------------\n\nYou can specify the order of rows in your response using the `ORDER BY` clause,\nwhich consists of one or more comma-separated sequences of: \n\n FieldName ('ASC' | 'DESC')?\n\nIf you don't specify `ASC` or `DESC` after a field name, the Google Ads API defaults to\n`ASC`.\n\nThe following `ORDER BY` clause sorts a campaign-level report by descending\nimpressions and ascending campaign name: \n\n ORDER BY metrics.impressions DESC, campaign.name ASC\n\nOrdering is not allowed:\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n- By attributes of non-selected resources\n- By non-selected metrics\n- By non-selected segments\n- For fields of the following types:\n - `MESSAGE`\n - Repeated fields\n - Attributes of repeated fields\n\nLimit the number of results\n---------------------------\n\nYou can limit the total number of results returned using the `LIMIT` clause.\nCombining this with results ordering, you can produce \"top N\" reports,\nsuch as a report containing the five campaigns with the highest impressions\nover the last 30 days: \n\n SELECT\n campaign.id,\n campaign.name,\n metrics.impressions\n FROM campaign\n WHERE segments.date DURING LAST_30_DAYS\n ORDER BY metrics.impressions DESC\n LIMIT 5\n\nFiltering is not allowed:\n\n- On segments without selecting them, except for \"core\" date segment fields.\n - The core date segment fields are `segments.date`, `segments.week`, `segments.month`, `segments.quarter`, and `segments.year`.\n- On fields of any message type except primitives (e.g.: Int64Value, StringValue, etc.)\n- On attributes of repeated fields of any message type except primitives (e.g.: Int64Value, StringValue, etc.)"]]