Skip to main content

在ClickHouse中选择查询

ClickHouse是一个SQL数据库,您可以通过编写与您已经熟悉的SELECT查询相同类型的查询来查询数据。例如:

SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
note

查看SQL参考以获取有关语法和可用子句和选项的更多详细信息。

注意响应以漂亮的表格格式返回:

┌─user_id─┬─message────────────────────────────────────────────┬───────────timestamp─┬──metric─┐
│ 102 │ Insert a lot of rows per batch │ 2022-03-21 00:00:00 │ 1.41421 │
│ 102 │ Sort your data based on your commonly-used queries │ 2022-03-22 00:00:00 │ 2.718 │
│ 101 │ Hello, ClickHouse! │ 2022-03-22 14:04:09 │ -1 │
│ 101 │ Granules are the smallest chunks of data read │ 2022-03-22 14:04:14 │ 3.14159 │
└─────────┴────────────────────────────────────────────────────┴─────────────────────┴─────────┘

4 rows in set. Elapsed: 0.008 sec.

添加FORMAT子句以指定ClickHouse支持的许多输出格式之一:

SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
FORMAT TabSeparated

在上面的查询中,输出以制表符分隔的形式返回:

Query id: 3604df1c-acfd-4117-9c56-f86c69721121

102 Insert a lot of rows per batch 2022-03-21 00:00:00 1.41421
102 Sort your data based on your commonly-used queries 2022-03-22 00:00:00 2.718
101 Hello, ClickHouse! 2022-03-22 14:04:09 -1
101 Granules are the smallest chunks of data read 2022-03-22 14:04:14 3.14159

4 rows in set. Elapsed: 0.005 sec.
note

ClickHouse支持70多种输入和输出格式,因此在数千个函数和所有数据格式之间,您可以使用ClickHouse执行一些令人印象深刻且快速的ETL样数据转换。事实上,您甚至不需要运行ClickHouse服务器来转换数据-您可以使用clickhouse-local工具。查看clickhouse-local的文档页面以获取详细信息。