Hive中的concatenate函數用于將兩個或多個字符串連接在一起
concatenate(string str1, string str2, ...)
參數:
示例:
假設我們有一個名為employees的表,其中包含以下列:employee_id, first_name, last_name, department。
現在,我們想要將first_name和last_name列連接在一起,以創建一個全名列。我們可以使用concatenate函數實現這一目標。
SELECT employee_id,
concatenate(first_name, ' ', last_name) AS full_name
FROM employees;
這將返回一個結果集,其中包含employee_id和full_name列。full_name列將包含每個員工的全名(first_name和last_name連接在一起)。
如果你想要連接更多的字符串列,只需在concatenate函數中添加更多的參數即可。例如:
SELECT employee_id,
concatenate(first_name, ' ', last_name, ' - ', department) AS full_name_with_department
FROM employees;
這將返回一個結果集,其中包含employee_id和full_name_with_department列。full_name_with_department列將包含每個員工的全名以及他們所在的部門。