英文:
Python to SQL using strip
问题
SELECT
TRIM(SUBSTRING(TableA.Col, 1, 2)) AS Column1,
TRIM(SUBSTRING(TableA.Col, 3, 12)) AS Column2
FROM TableA;
英文:
gday I would like to know how to convert the following python script to sql and with its source file being a txt file
Data = [
r[0: 2].strip(), # Column 1
r[2: 14].strip() # Column 2
]
I've loaded the txt file into a table with a single column called TableA
TRIM(SUBSTRING(TableA.Col, 0, 2)) AS Column1
,TRIM(SUBSTRING(TableA.Col, 2, 14)) AS Column2
but it doesnt look right - could someone point me in the right direction
答案1
得分: 1
r[0: 2]
--> SUBSTRING(TableA.Col, 1, 2)
r[2: 14]
--> SUBSTRING(TableA.Col, 3, 12)
英文:
Assuming r
is a string, then slicing syntax is [start:stop:step]
. Then r[0:2]
would mean start=0, stop=2 and index 2 is not included
SUBSTRING
syntax is SUBSTRING(string, start, length)
and first index is 1.
So
r[0: 2]
--> SUBSTRING(TableA.Col, 1, 2)
r[2: 14]
--> SUBSTRING(TableA.Col, 3, 12)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论