Hive中的concat_ws函数用于将多个字符串连接在一起,并在它们之间插入指定的分隔符
concat_ws(string str, string sep, [string... strings])
参数说明:
str:要连接的字符串。sep:用作分隔符的字符串。[string... strings]:可选参数,表示要连接的其他字符串。使用示例:
假设我们有一个名为employees的表,其中包含以下列:id,first_name,last_name和department。现在我们想要将first_name和last_name列连接起来,并在它们之间插入一个空格,然后将结果与department列连接起来。可以使用以下查询:
SELECT id,
concat_ws(' ', first_name, last_name) AS full_name,
department
FROM employees;
这将返回以下结果:
id | full_name | department
-----------------------------
1 | John Doe | HR
2 | Jane Smith | IT
3 | Michael Brown | Sales
在这个例子中,我们使用concat_ws函数将first_name和last_name列连接起来,并在它们之间插入一个空格。然后,我们将结果与department列连接起来,得到full_name列。