Select distinct first words of a field

前端 未结 2 2046
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 21:06

i would like to be able to do a select query, taking only the distinct first words of the string, excluding the last one. If not clear, here is the result i\'d like to have

相关标签:
2条回答
  • 2021-01-16 21:06
    SELECT DISTINCT TRIM(SUBSTRING(model, 1, LENGTH(TRIM(model))-4))
    
    0 讨论(0)
  • 2021-01-16 21:16

    You can reverse the string to find the first space " "

    SQL Demo

    SELECT DISTINCT RTRIM(REVERSE(SUBSTRING(REVERSE(`model`),LOCATE(" ",REVERSE(`model`)))))
    FROM Table1
    

    OUTPUT

    0 讨论(0)
提交回复
热议问题