- 表具体说明
- Impala - 创建表语句
- Impala - 插入语句
- Impala - 选择语句
- Impala - 描述语句
- Impala - 更改表
- Impala - 删除一个表
- Impala - 截断表
- Impala - 显示表
- Impala - 创建视图
- Impala - 改变视图
- Impala - 放下视图
- Impala - 条款
- Impala - 按条款排序
- Impala - Group By 子句
- Impala - 拥有子句
- Impala - 限制条款
- Impala - 抵消条款
- Impala - 联合条款
- Impala - 带子句
- Impala - 独特的运算符
- 黑斑羚有用的资源
- Impala - 快速指南
- Impala - 有用的资源
- Impala - 讨论
Impala - 抵消条款
一般来说,select查询结果集中的行从 0 开始。使用offset子句,我们可以决定应该从哪里考虑输出。例如,如果我们选择偏移量为0,则结果将与往常一样,如果我们选择偏移量为5,则结果从第五行开始。
句法
以下是 Impala 中offset子句的语法。
select data from table_name Group BY col_name;
例子
假设数据库my_db中有一个名为customer的表,其内容如下 -
[quickstart.cloudera:21000] > select * from customers; Query: select * from customers +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 3 | kaushik | 23 | Kota | 30000 | | 6 | Komal | 22 | MP | 32000 | | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 5 | Hardik | 27 | Bhopal | 40000 | | 2 | Khilan | 25 | Delhi | 15000 | | 8 | ram | 22 | vizag | 31000 | | 9 | robert | 23 | banglore | 28000 | | 7 | ram | 25 | chennai | 23000 | | 4 | Chaitali | 25 | Mumbai | 35000 | +----+----------+-----+-----------+--------+ Fetched 9 row(s) in 0.51s
您可以按照 id 的升序排列表中的记录,并将记录数限制为 4,使用limit和order by子句,如下所示。
Query: select * from customers order by id limit 4 +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 2 | Khilan | 25 | Delhi | 15000 | | 3 | kaushik | 23 | Kota | 30000 | | 4 | Chaitali | 25 | Mumbai | 35000 | +----+----------+-----+-----------+--------+ Fetched 4 row(s) in 0.64s
以下是offset子句的示例。在这里,我们按照 ID 的顺序获取客户表中的记录,并从第0 行开始打印前四行。
[quickstart.cloudera:21000] > select * from customers order by id limit 4 offset 0;
执行时,上述查询给出以下结果。
Query: select * from customers order by id limit 4 offset 0 +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 2 | Khilan | 25 | Delhi | 15000 | | 3 | kaushik | 23 | Kota | 30000 | | 4 | Chaitali | 25 | Mumbai | 35000 | +----+----------+-----+-----------+--------+ Fetched 4 row(s) in 0.62s
以同样的方式,您可以从客户表中从偏移量为 5 的行开始获取 4 条记录,如下所示。
[quickstart.cloudera:21000] > select * from customers order by id limit 4 offset 5; Query: select * from customers order by id limit 4 offset 5 +----+--------+-----+----------+--------+ | id | name | age | address | salary | +----+--------+-----+----------+--------+ | 6 | Komal | 22 | MP | 32000 | | 7 | ram | 25 | chennai | 23000 | | 8 | ram | 22 | vizag | 31000 | | 9 | robert | 23 | banglore | 28000 | +----+--------+-----+----------+--------+ Fetched 4 row(s) in 0.52s