本文介绍如何使用示例 KQL 查询来初步了解数据。
查询是处理数据和返回结果的只读请求。 该请求使用易于读取、创作和自动化的数据流模型以纯文本形式声明。 查询始终在特定表或数据库的上下文中运行。 查询至少由源数据引用和一个或多个按顺序应用的查询运算符组成,通过使用管道字符 (|) 来分隔运算符,以直观方式指示。
有关 Kusto 查询语言的详细信息,请参阅 Kusto 查询语言(KQL)概述。
先决条件
使用代码进行查询
可通过两种方式启动菜单来查询 KQL 表。
在左窗格中选择该表。 在以下示例中,已选择 yelllowtaxidata 。
选择顶部菜单中 包含代码的查询 。
另一种方法是将鼠标悬停在表格上,选择 ...(省略号),你会看到以下上下文菜单,其中包含代码选项相同的 查询 。
选择要运行的 KQL 查询 。 若要运行示例 SQL 查询,请选择 SQL,然后选择要运行的 SQL 查询。 查询会自动运行并显示结果,如下图所示。
示例查询
显示任何 100 条记录
// Use 'take' to view a sample number of records in the table and check the data.
yellowtaxidata
| take 100
过去 24 小时内引入的记录
// See the most recent data - records ingested in the last 24 hours.
yellowtaxidata
| where ingestion_time() between (now(-1d) .. now())
获取表架构
// View a representation of the schema as a table with column names, column type, and data type.
yellowtaxidata
| getschema
获取上次引入时间
// Check when the last record in the table was ingested.
yellowtaxidata
| summarize LastIngestionTime = max(ingestion_time())
显示记录总数
//See how many records are in the table.
yellowtaxidata
| count
汇总每小时引入次数
// This query returns the number of ingestions per hour in the given table.
yellowtaxidata
| summarize IngestionCount = count() by bin(ingestion_time(), 1h)
SQL:显示任何 100 条记录
-- View a sample of 100 records in the table.
select top 100 * from yellowtaxidata
SQL:显示记录总数
-- See how many records are in the table.
select count_big(*) from yellowtaxidata