透過集合功能整理內容
你可以依據偏好儲存及分類內容。
訂單結果
您可以使用 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 等)
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間: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.)"]]