且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据从一列拆分成多列&从多个表中选择数据

更新时间:2022-01-23 22:16:20

我在表student中有一个像'david#jones'这样的全名列。



所以如果你想将这些名字分隔为david和姓氏为jones

这里的查询就像



选择POSITION('#'IN FULLNAME)AS POS,SUBSTR(FULLNAME,1,POS-1)AS FNAME,SUBSTR(FULLNAME,POS + 1)AS LNAME

来自学生



列POS标识特殊字符的邮件,

下一个子字符串是从第一个字符串开始的字符到最后一个但是作为FNAME的特殊字符之一,从特殊字符到结尾的下一个位置被视为LNAME。
I have a column with fullname like 'david#jones' in table student.

so if you want to separate these like firstname as "david" and lastname as "jones"
here goes the query like

SELECT POSITION( '#' IN FULLNAME) AS POS ,SUBSTR(FULLNAME , 1,POS-1) AS FNAME,SUBSTR(FULLNAME,POS+1) AS LNAME
FROM STUDENT

The column POS identifies the postition of the special character,
the next sub string is taken form the first character to the last but one of the special character as FNAME and from the next position of the special character to the end is taken as LNAME.