The Search Ads 360 Query Language allows you to build search queries to retrieve
reporting data and resource metadata using the Search Ads 360 Reporting API.

## Search services

You can use the Search Ads 360 Query Language to query the API using:

[`SearchAds360Service`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchads360service)

:   Use this service to query resources and their related attributes, segments,
    and metrics. There are two methods, *`Search`* and *`SearchStream`*.

    `SearchAds360Service` queries return a list of
    [`SearchAds360Row`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchads360row)
    instances:

    - Each row represents a resource.
    - If requested, rows include attributes and metric fields.
    - If you request segments, additional rows are included for each segment-resource tuple.

    See [Create search reports](https://developers.google.com/search-ads/reporting/concepts/search-reports) for more
    information.

[`SearchAds360FieldService`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchads360fieldservice)

:   Use this service to query for metadata about available fields and resources.
    The service provides a catalog of queryable fields with specifics about
    their compatibility and type.

    `SearchAds360FieldService` returns a list of
    [`SearchAds360Field`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.resources#searchads360field)
    instances:

    - Each field contains details about the requested field.

    See [Retrieve resource metadata](https://developers.google.com/search-ads/reporting/concepts/field-service) to learn more.

## Basic query examples

The following sections provide basic query examples that you can adapt to build
your own queries.

### Query for attributes of a resource

This is a basic query for attributes of the `campaign` resource that returns the
campaign ID, name, and status:

    SELECT
      campaign.id,
      campaign.name,
      campaign.status
    FROM campaign
    ORDER BY campaign.id

- Each returned `SearchAds360Row` represents a `campaign` object.
- Rows are populated with the selected fields (including the given campaign's
  `resource_name`).

- The query orders by campaign ID.

See [`campaign`](https://developers.google.com/search-ads/reporting/api/reference/fields/v0/campaign) for other available fields you can use in
your queries.

### Query for metrics

This is a basic query for metrics related to attributes of the `campaign`
resource:

    SELECT
      campaign.id,
      campaign.name,
      campaign.status,
      metrics.impressions
    FROM campaign
    WHERE campaign.status = 'PAUSED'
      AND metrics.impressions > 1000
    ORDER BY campaign.id

- The query returns campaigns with the status `PAUSED` and more than 1000
  impressions.

- Each returned `SearchAds360Row` has a `metrics` field populated with the
  selected metrics.

- The query orders by campaign ID.

See [`metrics`](https://developers.google.com/search-ads/reporting/api/reference/fields/v0/metrics) for other available metrics you can use in
your queries.

### Query for segments

This is a basic query for segments related to attributes of the `campaign`
resource:

    SELECT
      campaign.id,
      campaign.name,
      campaign.status,
      metrics.impressions,
      segments.date,
    FROM campaign
    WHERE campaign.status = 'PAUSED'
      AND metrics.impressions > 1000
      AND segments.date during LAST_30_DAYS
    ORDER BY campaign.id

- The query returns campaigns with the status `PAUSED` and more than 1000
  impressions.

- It segments the data by date.

- As a result of the segmentation, each `SearchAds360Row` represents a tuple
  of a campaign and the date segment.

- The query orders by campaign ID.

See [`segments`](https://developers.google.com/search-ads/reporting/api/reference/fields/v0/segments#segments.date) for a list of segments you
can use in your queries and
[Segmentation](https://developers.google.com/search-ads/reporting/concepts/search-reports#segmentation) for more information
about segmenting your reports.

### Query for attributes of a related resource

This is a basic query on the `campaign` resource that joins attributes of the
`bidding_strategy` resource, if available. This type of related resource is
known as an attributed resource.

    SELECT
      campaign.id,
      campaign.name,
      campaign.status,
      bidding_strategy.name
    FROM campaign
    ORDER BY campaign.id

- The query selects campaign attributes and related attributes from each
  campaign selected.

- Each returned `SearchAds360Row` represents a `campaign` object populated
  with the selected campaign attributes, as well as, the selected bidding
  strategy attribute, `bidding_strategy.name`.

See [`campaign`](https://developers.google.com/search-ads/reporting/api/reference/fields/v0/campaign#campaign.bidding_strategy_type) to find out
which attributed resources are available for campaign queries.

### Query for field metadata

You can use
[`SearchAds360FieldService`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchads360fieldservice)
to retrieve field metadata.

This is a basic query for field metadata:

```sql
SELECT
  name,
  category,
  selectable,
  filterable,
  sortable,
  selectable_with,
  data_type,
  is_repeated
WHERE name = RESOURCE/FIELD
```

- Replace RESOURCE OR FIELD with either a resource (such as, `customer` or `campaign`) or a field (such as, `campaign.id`, `metrics.impressions`, or `ad_group.id`).

> [!NOTE]
> **Note:** These is no `FROM` clause in a query for field metadata.

See [Retrieve resource metadata](https://developers.google.com/search-ads/reporting/concepts/field-service) for more information
about retrieving field metadata.

## Learn more

Learn more about how to build queries in the Search Ads 360 Reporting API:

- [Query structure and clauses](https://developers.google.com/search-ads/reporting/query/query-structure)
- [Date ranges](https://developers.google.com/search-ads/reporting/query/date-ranges)
- [Zero metrics](https://developers.google.com/search-ads/reporting/query/zero-metrics)
- [Sample queries](https://developers.google.com/search-ads/reporting/query/sample-queries)
- [Query grammar](https://developers.google.com/search-ads/reporting/query/query-grammar)