> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 查询 ClickHouse 数据

> 了解如何查询 ClickHouse 数据

<a href="/docs/get-started/quickstarts/home" onClick={(e) => { e.preventDefault(); window.location.href = (window.location.pathname.startsWith('/docs') ? '/docs' : '') + '/get-started/quickstarts/home'; }} className="inline-flex items-center gap-1.5 text-sm text-gray-500 dark:text-zinc-500 hover:text-gray-900 dark:hover:text-[#fdff75] transition-colors font-normal no-underline"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="shrink-0"><path d="M19 12H5" /><path d="M12 19l-7-7 7-7" /></svg>All quickstarts</a>

<div className="mt-2 flex flex-wrap gap-2">
  <Badge size="lg" color="blue">实时分析</Badge>
  <Badge size="lg" color="blue">数据仓储</Badge>
  <Badge size="lg" color="blue">可观测性</Badge>
  <Badge size="lg" color="blue">AI/ML</Badge>
  <Badge size="lg" color="orange">OSS</Badge>
</div>

ClickHouse 是一个 SQL 数据库，你可以像平时一样编写熟悉的 `SELECT` 查询来查询数据。例如：

```sql theme={null}
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
```

<Note>
  有关语法以及可用子句和选项的更多信息，请参阅 [SQL 参考](/docs/zh/reference/statements/select/index)。
</Note>

注意，返回结果会以清晰的表格形式显示：

```response theme={null}
┌─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 支持的多种输出格式](/docs/zh/reference/formats/index#formats-overview) 中的一种：

```sql theme={null}
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
FORMAT TabSeparated
```

在上述查询中，输出将以制表符分隔的形式返回：

```response theme={null}
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 server 就能转换数据——只需使用 `clickhouse-local` 工具即可。详情请参阅 [`clickhouse-local` 文档页面](/docs/zh/concepts/features/interfaces/cli)。
</Note>

<div className="mt-8">
  <a href="/docs/get-started/quickstarts/home" onClick={(e) => { e.preventDefault(); window.location.href = (window.location.pathname.startsWith('/docs') ? '/docs' : '') + '/get-started/quickstarts/home'; }} className="inline-flex items-center gap-1.5 text-sm text-gray-500 dark:text-zinc-500 hover:text-gray-900 dark:hover:text-[#fdff75] transition-colors font-normal no-underline"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="shrink-0"><path d="M19 12H5" /><path d="M12 19l-7-7 7-7" /></svg>All quickstarts</a>
</div>
