[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThe Google Ads Query Language allows you to query the Google Ads API for resources, attributes, segments, and metrics, as well as metadata about available fields.\u003c/p\u003e\n"],["\u003cp\u003eYou can use the \u003ccode\u003eGoogleAdsService\u003c/code\u003e to retrieve resources and their related data, and the \u003ccode\u003eGoogleAdsFieldService\u003c/code\u003e to retrieve metadata about available fields.\u003c/p\u003e\n"],["\u003cp\u003eQueries can include filters, ordering, and joins to related resources, enabling complex data retrieval and analysis.\u003c/p\u003e\n"],["\u003cp\u003eResults from queries can be used to programmatically modify and update resources through the Google Ads API.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries provide code examples to help you get started with using the Google Ads Query Language.\u003c/p\u003e\n"]]],[],null,["# Google Ads Query Language\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nQuery for resource or metadata information\n------------------------------------------\n\nThe Google Ads Query Language can query the Google Ads API for the following types of information:\n\n- Resources and their related attributes, segments, and metrics using [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService)\n *Search* or *SearchStream* :\n The result from a GoogleAdsService query is a list of\n [`GoogleAdsRow`](/google-ads/api/reference/rpc/v21/GoogleAdsRow) instances, with each `GoogleAdsRow`\n representing a resource.\n\n If any attributes or metrics are requested, then the\n row also includes those fields. If any segments are requested, then the\n response also shows an additional row for each segment-resource tuple.\n- Metadata about available fields and resources in [`GoogleAdsFieldService`](/google-ads/api/reference/rpc/v21/GoogleAdsFieldService):\n This service provides a catalog of queryable fields with specifics about their\n compatibility and type.\n\n The result from a `GoogleAdsFieldService` query is\n a list of [`GoogleAdsField`](/google-ads/api/reference/rpc/v21/GoogleAdsField) instances, with each\n `GoogleAdsField` containing details about the requested field.\n\n### Query for resource attributes\n\nHere is an example of a basic query for attributes of the campaign resource that\nillustrates how to return the campaign ID, name, and status: \n\n SELECT\n campaign.id,\n campaign.name,\n campaign.status\n FROM campaign\n ORDER BY campaign.id\n\nThis query orders by campaign ID. Each resulting `GoogleAdsRow` represents\na `campaign` object populated with the selected fields, including the\ncampaign's `resource_name`.\n\nTo find out what other fields are available for campaign queries, consult the\n[`Campaign` reference documentation](/google-ads/api/reference/rpc/v21/Campaign).\n\n### Query for metrics\n\nAlongside selected attributes for a given resource, you can also query for\nrelated metrics: \n\n SELECT\n campaign.id,\n campaign.name,\n campaign.status,\n metrics.impressions\n FROM campaign\n WHERE campaign.status = 'PAUSED'\n AND metrics.impressions \u003e 1000\n ORDER BY campaign.id\n\nThis query filters for only the campaigns that have a status of `PAUSED` and\nhave had greater than 1000 impressions, while ordering by campaign ID. Each\nresulting `GoogleAdsRow` would have a `metrics` field populated with the\nselected metrics.\n\nFor a list of queryable metrics, consult the [`Metrics`\ndocumentation](/google-ads/api/reference/rpc/v21/Metrics).\n\n### Query for segments\n\nAlongside selected attributes for a given resource, you can also query for\nrelated segments: \n\n SELECT\n campaign.id,\n campaign.name,\n campaign.status,\n metrics.impressions,\n segments.date,\n FROM campaign\n WHERE campaign.status = 'PAUSED'\n AND metrics.impressions \u003e 1000\n AND segments.date during LAST_30_DAYS\n ORDER BY campaign.id\n\nSimilar to querying for metrics, this query filters for only the campaigns that\nhave a status of `PAUSED` and have had greater than 1000 impressions. However,\nthis query segments the data by date. This leads to each resulting\n`GoogleAdsRow` representing a tuple of a campaign and the date `Segment`.\nSegmenting splits the selected metrics, grouping by each segment in the SELECT\nclause.\n\nFor a list of queryable segments, consult the\n[`Segments` documentation](/google-ads/api/reference/rpc/v21/Segments).\n\n### Query for attributes of a related resource\n\nIn a query for a given resource, you may be able to join against other related\nresources if available. These related resources are known as \"attributed\nresources\". You can join against attributed resources implicitly by selecting an\nattribute in your query. \n\n SELECT\n campaign.id,\n campaign.name,\n campaign.status,\n bidding_strategy.name\n FROM campaign\n ORDER BY campaign.id\n\nThis query not only selects campaign attributes, but also pulls in related\nattributes from each campaign selected. Each resulting `GoogleAdsRow` represents\na `campaign` object populated with the selected campaign attributes, as well as\nthe selected bidding strategy attribute `bidding_strategy.name`.\n\nTo find out what attributed resources are available for campaign queries,\nconsult the [`Campaign` reference documentation](/google-ads/api/reference/rpc/v21/Campaign).\n\nMutate based on query results\n-----------------------------\n\nWhen querying for a given resource, you can immediately take those returned\nresults as objects, modify them, and send them back to the mutate method in that\nresource's service. Here is a sample workflow:\n1. Execute a query for all campaigns that are currently `PAUSED` and have\nimpressions greater than 1000.\n1. Get the `Campaign` object from the `campaign` field of each `GoogleAdsRow` in\nthe response.\n1. Change the status of each campaign from `PAUSED` to `ENABLED`.\n1. Call [`CampaignService.MutateCampaigns`](/google-ads/api/reference/rpc/v21/CampaignService)\nwith the modified campaigns to update them.\n\nField metadata\n--------------\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nQueries sent to `GoogleAdsFieldService` are meant for retrieving field metadata.\nThis information can be used to understand how the fields can be used together\nin a query. Since data is available from the API and it provides the necessary\nmetadata needed to validate or build a query, this allows for developers to do\nso programmatically. Here's a\ntypical query for metadata: \n\n SELECT\n name,\n category,\n selectable,\n filterable,\n sortable,\n selectable_with,\n data_type,\n is_repeated\n WHERE name = \"\u003cINSERT_RESOURCE_OR_FIELD\u003e\"\n\nYou can replace `\u003cINSERT_RESOURCE_OR_FIELD\u003e` in this query with either a\nresource (such as `customer` or `campaign`) or field (such as `campaign.id`,\n`metrics.impressions`, or `ad_group.id`).\n| **Key Point:** Note that there's no `FROM` clause in this query.\n\nFor a list of queryable fields, consult the\n[`GoogleAdsField` documentation](/google-ads/api/reference/rpc/v21/GoogleAdsField).\n\nCode examples\n-------------\n\nThe [client libraries](/google-ads/api/docs/client-libs) have examples of using the\nGoogle Ads Query Language in `GoogleAdsService`. The **basic operations** folder has\nexamples such as `GetCampaigns`, `GetKeywords`, and `SearchForGoogleAdsFields`."]]