Split FirstName and LastName in sqlite

后端 未结 2 1727
甜味超标
甜味超标 2020-12-09 12:05

I have a table in sqlite db called [tblbook] with a column [authors]. What I am trying to do in the sql is to split the author values to firstname and the lastname and sort

2条回答
  •  生来不讨喜
    2020-12-09 12:28

    Another way (a little shorter) to write this would be

    SELECT 
      substr(BookAuthor, 1, instr(BookAuthor, ' ') - 1) AS first_name,
      substr(BookAuthor,    instr(BookAuthor, ' ') + 1) AS last_name
    FROM tblBook where id=3
    ORDER BY last_name
    

    This would apply for version 3.7.15 and beyond.

提交回复
热议问题