SHOW TABLES 可用于列出账户中的表。表名是你在配置 Workers binding 时指定为 dataset 的名称(更多信息请参阅 Workers Analytics Engine 快速入门)。当你在 Worker 中写入事件数据时,表会自动创建。
SHOW TABLES
[FORMAT <format>]请参阅 FORMAT clause for the available FORMAT options.
SHOW TIMEZONES 可用于列出 SQL API 支持的所有时区。大多数常见时区均受支持。
SHOW TIMEZONES
[FORMAT <format>]SHOW TIMEZONE 返回 SQL API 当前使用的默认时区。该值应始终为 Etc/UTC。
SHOW TIMEZONE
[FORMAT <format>]SELECT is used to query tables.
用法:
SELECT <expression_list>
[FROM <table>|(<subquery>)]
[WHERE <expression>]
[GROUP BY <expression>, ...]
[HAVING <expression>]
[ORDER BY <expression_list>]
[LIMIT <n>|ALL]
[FORMAT <format>]下方可找到每个子句的语法。示例查询请参阅 SQL API 文档。
SELECT 子句指定结果中包含的列列表。
可以使用 AS 关键字为列设置别名。
用法:
SELECT <expression> [AS <alias>], ...示例:
-- return the named columns
SELECT blob2, double3
-- return all columns
SELECT *
-- alias columns to more descriptive names
SELECT
blob2 AS probe_name,
double3 AS temperature此外,可使用支持的函数和运算符代替列名:
SELECT
blob2 AS probe_name,
double3 AS temp_c,
double3*1.8+32 AS temp_f -- compute a value
SELECT
blob2 AS probe_name,
if(double3 <= 0, 'FREEZING', 'NOT FREEZING') AS description -- use of functions
SELECT
blob2 AS probe_name,
avg(double3) AS avg_temp -- aggregation functionFROM 用于指定查询的数据来源。
用法:
FROM <table_name>|(subquery)示例:
-- query data written to a workers dataset called "temperatures"
FROM temperatures
-- use a subquery to manipulate the table
FROM (
SELECT
blob1 AS probe_name,
count() as num_readings
FROM
temperatures
GROUP BY
probe_name
)请注意,查询只能操作单个表。 UNION, JOIN etc. are not currently supported.
WHERE 用于在分组和聚合之前筛选查询返回的行。
用法:
WHERE <condition><condition> 可以是求值为 boolean 的任意表达式。
支持包含函数和运算符的表达式。
要在分组和聚合后筛选结果,请使用 HAVING 子句 instead.
示例:
-- simple comparisons
WHERE blob1 = 'test'
WHERE double1 = 4
-- inequalities
WHERE double1 > 4
-- use of operators (see below for supported operator list)
WHERE double1 + double2 > 4
WHERE blob1 = 'test1' OR blob2 = 'test2'
-- expression using inequalities, functions and operators
WHERE if(unit = 'f', (temp-32)/1.8, temp) <= 0使用聚合函数时,GROUP BY 指定运行聚合的分组。
用法:
GROUP BY <expression>, ...例如,如果你有一个温度读数表:
-- return the average temperature for each probe
SELECT
blob1 AS probe_name,
avg(double1) AS average_temp
FROM temperature_readings
GROUP BY probe_name通常 <expression> 可以是列名,但也可以在此提供复杂表达式。 可以提供多个表达式或列名,用逗号分隔。
HAVING 用于在分组和聚合后筛选结果。
用法:
HAVING <condition><condition> 可以是求值为 boolean 的任意表达式,可引用聚合函数或分组列。
与在分组前筛选行的 WHERE 不同,HAVING 在聚合后筛选分组。 这允许你基于聚合值进行筛选。
示例:
-- filter groups where the average is greater than 10
SELECT
blob1 AS probe_name,
avg(double1) AS average_temp
FROM temperature_readings
GROUP BY probe_name
HAVING average_temp > 10
-- filter groups with more than 100 readings
SELECT
blob1 AS probe_name,
count() AS num_readings
FROM temperature_readings
GROUP BY probe_name
HAVING num_readings > 100
-- combine multiple conditions
SELECT
blob1 AS city,
avg(double1) AS avg_temp,
count() AS readings
FROM weather_data
GROUP BY city
HAVING avg_temp > 20 AND readings >= 50ORDER BY 可用于控制返回行的顺序。
用法:
ORDER BY <expression> [ASC|DESC], ...<expression> 可以是列名。
ASC 或 DESC 决定排序是升序还是降序。ASC 是默认值,可省略。
示例:
-- order by double2 then double3, both in ascending order
ORDER BY double2, double3
-- order by double2 in ascending order then double3 is descending order
ORDER BY double2, double3 DESCLIMIT 指定返回的最大行数。
用法:
LIMIT <n>|ALL提供返回的最大行数,或使用 ALL 表示无限制。
例如:
LIMIT 10 -- return at most 10 rowsOFFSET 指定在查询结果中跳过的行数。
用法:
OFFSET <n>例如:
OFFSET 10 -- skip the first 10 result rowsFORMAT 控制返回数据的编码方式。
用法:
FORMAT [JSON|JSONEachRow|TabSeparated]如果不包含 format 子句,将使用 JSON 默认格式。
通过设置 format 覆盖默认值。 例如:
FORMAT JSONEachRow支持以下格式:
数据作为包含 schema 数据的单个 JSON 对象返回:
{
"meta": [
{
"name": "<column 1 name>",
"type": "<column 1 type>"
},
{
"name": "<column 2 name>",
"type": "<column 2 type>"
},
...
],
"data": [
{
"<column 1 name>": "<column 1 value>",
"<column 2 name>": "<column 2 value>",
...
},
{
"<column 1 name>": "<column 1 value>",
"<column 2 name>": "<column 2 value>",
...
},
...
],
"rows": 10
}数据以每行一个单独的 JSON 对象返回。 行以换行符分隔,没有 header 行或 schema 数据:
{"<column 1 name>": "<column 1 value>", "<column 2 name>": "<column 2 value>"}
{"<column 1 name>": "<column 1 value>", "<column 2 name>": "<column 2 value>"}
...数据以换行符分隔的行返回。 列以 tab 分隔。没有 header。
column 1 value column 2 value
column 1 value column 2 value
...