How to substring a MySQL table column

后端 未结 6 2091
借酒劲吻你
借酒劲吻你 2020-12-25 09:32

I want to select a field from table and substring it.

For example:

VAN1031 --> 1031

I tried this, but is improper syntax:

<
6条回答
  •  庸人自扰
    2020-12-25 10:25

    Sometimes you need to catch the column without some last characters. For example, I have:

    This is a string
    

    Let's say that for some reason I want column without last 6 characters:

    This is a 
    

    We can do (using @bluefeet 's answer and LENGHT):

    select substring(col1, 1,LENGTH(col1)-7)
    from table1
    

    It was only an example, but you got the idea, I'm using to fix a wrong database import.

提交回复
热议问题