如何从特定字符开始得到结果

zkure5ic  于 2021-06-02  发布在  Hadoop
关注(0)|答案(2)|浏览(237)

我在学Hive。假设我有如下表格,

t1

id  name 
 1   ram
 2   rahim 
 3   yesudas
 4   george 
 5   yogesh

现在我要写的是sql,

select name
from t1
where name like 'r%'

从r开始命名的结果是,

id  name 
 1   ram
 2   rahim

如何在Hive中实现这一点。请帮助

s4chpxco

s4chpxco1#

表创建:

create table t1 (id int,name string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;

查询:

select * from t1 where name like 'r%';

输出:

1 ram
   2 rahim
k2arahey

k2arahey2#

您可以运行相同的查询。
Hive>

CREATE TABLE t1(
 id int, 
 name string)
 ROW FORMAT DELIMITED 
 FIELDS TERMINATED BY ',' 
 LINES TERMINATED BY '\n';

正常时间:0.625秒

hive> load data local inpath '/home/amit/data.txt' into table t1;

正在将数据加载到表eis\ U app.t1表eis\ U app.t1统计:[numfiles=1,totalsize=44]确定所用时间:1.22秒

hive> select * from t1;

OK
1   ram
2   rahim 
3   yesudas
4   george 
5   yogesh
Time taken: 0.098 seconds, Fetched: 5 row(s)

hive> select * from t1 where name like 'r%';

    OK
    1   ram
    2   rahim 
    Time taken: 0.107 seconds, Fetched: 2 row(s)
    hive>

相关问题