Ngữ pháp ngôn ngữ truy vấn của Google Ads
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.
ondemand_video
Video: Xác thực truy vấn
Sau đây là tài liệu tham khảo về ngữ pháp Ngôn ngữ truy vấn Google Ads (theo ký hiệu biểu thức chính quy):
Query -> SelectClause FromClause WhereClause? OrderByClause?
LimitClause? ParametersClause?
SelectClause -> SELECT FieldName (, FieldName)*
FromClause -> FROM ResourceName
WhereClause -> WHERE Condition (AND Condition)*
OrderByClause -> ORDER BY Ordering (, Ordering)*
LimitClause -> LIMIT PositiveInteger
ParametersClause -> PARAMETERS Literal = Value (, Literal = Value)*
Condition -> FieldName Operator Value
Operator -> = | != | > | >= | < | <= | IN | NOT IN |
LIKE | NOT LIKE | CONTAINS ANY | CONTAINS ALL |
CONTAINS NONE | IS NULL | IS NOT NULL | DURING |
BETWEEN | REGEXP_MATCH | NOT REGEXP_MATCH
Value -> Literal | LiteralList | Number | NumberList | String |
StringList | Function
Ordering -> FieldName (ASC | DESC)?
FieldName -> [a-z] ([a-zA-Z0-9._])*
ResourceName -> [a-z] ([a-zA-Z_])*
StringList -> ( String (, String)* )
LiteralList -> ( Literal (, Literal)* )
NumberList -> ( Number (, Number)* )
PositiveInteger -> [1-9] ([0-9])*
Number -> -? [0-9]+ (. [0-9] [0-9]*)?
String -> (' Char* ') | (" Char* ")
Literal -> [a-zA-Z0-9_]*
Function -> LAST_14_DAYS | LAST_30_DAYS | LAST_7_DAYS |
LAST_BUSINESS_WEEK | LAST_MONTH | LAST_WEEK_MON_SUN |
LAST_WEEK_SUN_SAT | THIS_MONTH | THIS_WEEK_MON_TODAY |
THIS_WEEK_SUN_TODAY | TODAY | YESTERDAY
?
biểu thị một phần tử không bắt buộc
*
có nghĩa là không có hoặc có nhiều phần tử; +
có nghĩa là có một hoặc nhiều phần tử
(xxxxxx)
biểu thị một nhóm
[a-z0-9]
biểu thị các dải ký tự
|
có nghĩa là "hoặc"
Quy tắc và giới hạn
Toán tử REGEXP_MATCH
sử dụng cú pháp RE2.
Để so khớp một giá trị cố định [
, ]
, %
hoặc _
bằng toán tử LIKE
, hãy đặt ký tự trong dấu ngoặc vuông. Ví dụ: điều kiện sau đây khớp với tất cả các giá trị campaign.name
bắt đầu bằng [Earth_to_Mars]
:
campaign.name LIKE '[[]Earth[_]to[_]Mars[]]%'
Bạn chỉ có thể sử dụng toán tử LIKE
trên một trường chuỗi, chứ không phải một mảng.
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\u003eGoogle Ads Query Language (GAQL) uses a specific syntax to construct queries for retrieving data from Google Ads accounts, similar to SQL.\u003c/p\u003e\n"],["\u003cp\u003eGAQL supports various clauses like \u003ccode\u003eSELECT\u003c/code\u003e, \u003ccode\u003eFROM\u003c/code\u003e, \u003ccode\u003eWHERE\u003c/code\u003e, \u003ccode\u003eORDER BY\u003c/code\u003e, \u003ccode\u003eLIMIT\u003c/code\u003e, and \u003ccode\u003ePARAMETERS\u003c/code\u003e for data manipulation.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eWHERE\u003c/code\u003e clause allows filtering data based on conditions using operators like \u003ccode\u003e=\u003c/code\u003e, \u003ccode\u003e!=\u003c/code\u003e, \u003ccode\u003e>\u003c/code\u003e, \u003ccode\u003e<\u003c/code\u003e, \u003ccode\u003eIN\u003c/code\u003e, \u003ccode\u003eLIKE\u003c/code\u003e, \u003ccode\u003eCONTAINS\u003c/code\u003e, and others.\u003c/p\u003e\n"],["\u003cp\u003eGAQL provides built-in functions such as \u003ccode\u003eLAST_14_DAYS\u003c/code\u003e, \u003ccode\u003eTHIS_MONTH\u003c/code\u003e, \u003ccode\u003eTODAY\u003c/code\u003e, etc., for convenient date range selection within queries.\u003c/p\u003e\n"],["\u003cp\u003eWhen using operators like \u003ccode\u003eLIKE\u003c/code\u003e, special characters need to be escaped with square brackets for literal matching.\u003c/p\u003e\n"]]],[],null,["# Google Ads Query Language Grammar\n\nondemand_video\n[Video: Validating Queries](https://www.youtube.com/watch?v=pBpFEaXvADY&list=None&start=11)\n\nHere is the Google Ads Query Language grammar reference (in regular expression notation): \n\n```googlesql\nQuery -\u003e SelectClause FromClause WhereClause? OrderByClause?\n LimitClause? ParametersClause?\nSelectClause -\u003e SELECT FieldName (, FieldName)*\nFromClause -\u003e FROM ResourceName\nWhereClause -\u003e WHERE Condition (AND Condition)*\nOrderByClause -\u003e ORDER BY Ordering (, Ordering)*\nLimitClause -\u003e LIMIT PositiveInteger\nParametersClause -\u003e PARAMETERS Literal = Value (, Literal = Value)*\n\nCondition -\u003e FieldName Operator Value\nOperator -\u003e = | != | \u003e | \u003e= | \u003c | \u003c= | IN | NOT IN |\n LIKE | NOT LIKE | CONTAINS ANY | CONTAINS ALL |\n CONTAINS NONE | IS NULL | IS NOT NULL | DURING |\n BETWEEN | REGEXP_MATCH | NOT REGEXP_MATCH\nValue -\u003e Literal | LiteralList | Number | NumberList | String |\n StringList | Function\nOrdering -\u003e FieldName (ASC | DESC)?\n\nFieldName -\u003e [a-z] ([a-zA-Z0-9._])*\nResourceName -\u003e [a-z] ([a-zA-Z_])*\n\nStringList -\u003e ( String (, String)* )\nLiteralList -\u003e ( Literal (, Literal)* )\nNumberList -\u003e ( Number (, Number)* )\n\nPositiveInteger -\u003e [1-9] ([0-9])*\nNumber -\u003e -? [0-9]+ (. [0-9] [0-9]*)?\nString -\u003e (' Char* ') | (\" Char* \")\nLiteral -\u003e [a-zA-Z0-9_]*\n\nFunction -\u003e LAST_14_DAYS | LAST_30_DAYS | LAST_7_DAYS |\n LAST_BUSINESS_WEEK | LAST_MONTH | LAST_WEEK_MON_SUN |\n LAST_WEEK_SUN_SAT | THIS_MONTH | THIS_WEEK_MON_TODAY |\n THIS_WEEK_SUN_TODAY | TODAY | YESTERDAY\n```\n\n`?`indicates an optional element \n\n`*` means zero or more; `+` means one or more \n\n`(xxxxxx)` indicates a grouping \n\n`[a-z0-9]` signifies character ranges \n\n`|` stands for \"or\"\n\nRules and limitations\n---------------------\n\n- The `REGEXP_MATCH` operator uses [RE2\n syntax](//github.com/google/re2/wiki/Syntax).\n\n- To match a literal `[`, `]`, `%`, or `_` using the `LIKE` operator, surround\n the character in square brackets. For example, the following condition matches\n all `campaign.name` values that start with `[Earth_to_Mars]`:\n\n campaign.name LIKE '[[]Earth[_]to[_]Mars[]]%'\n\n- The `LIKE` operator can only be used on a string field, not an array."]]