จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
จัดเรียงผลการค้นหา
คุณระบุลำดับของแถวในการตอบกลับได้โดยใช้คําสั่ง ORDER BY
ซึ่งประกอบด้วยลําดับที่คั่นด้วยคอมมาอย่างน้อย 1 รายการของรายการต่อไปนี้
FieldName ('ASC' | 'DESC')?
หากคุณไม่ได้ระบุ ASC
หรือ DESC
หลังชื่อฟิลด์ Google Ads API จะใช้ค่าเริ่มต้นเป็น
ASC
ORDER BY
อนุประโยคต่อไปนี้จะจัดเรียงรายงานระดับแคมเปญตามการแสดงผลจากมากไปน้อย
และชื่อแคมเปญจากน้อยไปมาก
ORDER BY metrics.impressions DESC, campaign.name ASC
ไม่อนุญาตให้สั่งซื้อสิ่งต่อไปนี้
- ตามแอตทริบิวต์ของทรัพยากรที่ไม่ได้เลือก
- ตามเมตริกที่ไม่ได้เลือก
- ตามกลุ่มที่ไม่ได้เลือก
- สำหรับฟิลด์ประเภทต่อไปนี้
MESSAGE
- เขตข้อมูลที่ซ้ำได้
- แอตทริบิวต์ของฟิลด์ที่ซ้ำได้
จำกัดจำนวนผลลัพธ์
คุณจำกัดจำนวนผลลัพธ์ทั้งหมดที่แสดงได้โดยใช้คําสั่ง LIMIT
การรวมข้อมูลนี้กับการจัดลำดับผลลัพธ์จะช่วยให้คุณสร้างรายงาน "N อันดับแรก" ได้
เช่น รายงานที่มีแคมเปญ 5 รายการที่มีการแสดงผลสูงสุด
ในช่วง 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 Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 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.)"]]