gpt4 book ai didi

netezza - 拆分名字和姓氏 Netezza

转载 作者:行者123 更新时间:2023-12-01 00:48:32 27 4
gpt4 key购买 nike

我有一个列,其中有一个用空格分隔的客户的名字和姓氏。我会写什么代码来解析他们两个?我试过这个,但它不起作用。

SELECT LEFT (CUSTOMER_NAME, CHARINDEX(' ', CUSTOMER_NAME)) as CUST_1ST_1_NM,
substring(CUSTOMER_NAME, CHARINDEX(' ', CUSTOMER_NAME)+1, len(CUSTOMER_NAME)-(CHARINDEX(' ', CUSTOMER_NAME)-1)) as CUST_LAST_1_NM
from CUSTOMER_TABLE

谢谢!

最佳答案

像这样使用 INSTR 和 SUBSTR 是第一个想到的方法。

select * from test_table;
CUSTOMER_NAME
---------------
foo bar
(1 row)

select substr(CUSTOMER_NAME, 0, instr(CUSTOMER_NAME, ' ')) first_name,
substr(CUSTOMER_NAME,instr(CUSTOMER_NAME, ' ') +1) last_name
from test_table;
FIRST_NAME | LAST_NAME
------------+-----------
foo | bar
(1 row)

关于netezza - 拆分名字和姓氏 Netezza,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32747607/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com