SELECT & WHERE clause
Batch Streaming
The general syntax of the SELECT statement is: SELECT语句的一般语法为:
SELECT select_list FROM table_expression [ WHERE boolean_expression ]
The table_expression refers to any source of data. It could be an existing table, view, or VALUES clause, the joined results of multiple existing tables, or a subquery. Assuming that the table is available in the catalog, the following would read all rows from Orders. table_expression引用任何数据源。它可以是现有的表、视图或VALUES子句、多个现有表的联接结果或子查询。假设Orders表在目录中可用,下面将读取Orders中的所有行。
SELECT * FROM Orders
The select_list specification * means the query will resolve all columns. However, usage of * is discouraged in production because it makes queries less robust to catalog changes. Instead, a select_list can specify a subset of available columns or make calculations using said columns. For example, if Orders has columns named order_id, price, and tax you could write the following query: select_list 规范*表示查询将解析所有列。但是,不鼓励在生产中使用*,因为它会使查询对目录更改的鲁棒性降低。相反,select_list可以指定可用列的子集或使用所述列进行计算。例如,如果Orders具有名为order_id、price和tax的列,则可以编写以下查询:
SELECT order_id, price + tax FROM Orders
Queries can also consume from inline data using the VALUES clause. Each tuple corresponds to one row and an alias may be provided to assign names to each column. 查询还可以使用VALUES子句使用内联数据。每个元组对应一行,可以提供一个别名来为每个列指定名称。
SELECT order_id, price FROM (VALUES (1, 2.0), (2, 3.1)) AS t (order_id, price)
Rows can be filtered based on a WHERE clause. 可以基于WHERE子句筛选行。
SELECT price + tax FROM Orders WHERE id = 10
Additionally, built-in and user-defined scalar functions can be invoked on the columns of a single row. User-defined functions must be registered in a catalog before use. 此外,可以在单行的列上调用内置和用户定义的标量函数。用户定义的函数在使用前必须在目录中注册。
SELECT PRETTY_PRINT(order_id) FROM Orders
|