Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sắp xếp kết quả
Bạn có thể chỉ định thứ tự của các hàng trong phản hồi bằng cách sử dụng mệnh đề ORDER BY
, bao gồm một hoặc nhiều chuỗi được phân tách bằng dấu phẩy:
FieldName ('ASC' | 'DESC')?
Nếu bạn không chỉ định ASC
hoặc DESC
sau tên trường, thì API Google Ads sẽ mặc định là ASC
.
Mệnh đề ORDER BY
sau đây sắp xếp báo cáo cấp chiến dịch theo số lượt hiển thị giảm dần và tên chiến dịch tăng dần:
ORDER BY metrics.impressions DESC, campaign.name ASC
Không được phép đặt hàng:
- Theo thuộc tính của tài nguyên không được chọn
- Theo các chỉ số không được chọn
- Theo phân khúc chưa chọn
- Đối với các trường thuộc những loại sau:
MESSAGE
- Các trường lặp lại
- Thuộc tính của các trường lặp lại
Giới hạn số lượng kết quả
Bạn có thể giới hạn tổng số kết quả được trả về bằng mệnh đề LIMIT
.
Khi kết hợp với việc sắp xếp kết quả, bạn có thể tạo báo cáo "N hàng đầu", chẳng hạn như báo cáo chứa 5 chiến dịch có số lượt hiển thị cao nhất trong 30 ngày qua:
SELECT
campaign.id,
campaign.name,
metrics.impressions
FROM campaign
WHERE segments.date DURING LAST_30_DAYS
ORDER BY metrics.impressions DESC
LIMIT 5
Không được phép lọc:
- Trên các phân đoạn mà không chọn, ngoại trừ các trường phân đoạn ngày "cốt lõi".
- Các trường phân đoạn ngày cốt lõi là
segments.date
, segments.week
, segments.month
, segments.quarter
và segments.year
.
- Trên các trường thuộc mọi loại thông báo, ngoại trừ các kiểu dữ liệu nguyên thuỷ (ví dụ: Int64Value, StringValue, v.v.)
- Trên các thuộc tính của trường lặp lại thuộc mọi loại thông báo, ngoại trừ các kiểu dữ liệu nguyên thuỷ (ví dụ:
Int64Value, StringValue, v.v.)
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[[["\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.)"]]