How to concatenate strings with padding in sqlite

后端 未结 3 1596
一生所求
一生所求 2020-11-28 03:31

I have three columns in an sqlite table:

    Column1    Column2    Column3
    A          1          1
    A          1          2
    A          12                  


        
3条回答
  •  情深已故
    2020-11-28 04:25

    Just one more line for @tofutim answer ... if you want custom field name for concatenated row ...

    SELECT 
      (
        col1 || '-' || SUBSTR('00' || col2, -2, 2) | '-' || SUBSTR('0000' || col3, -4, 4)
      ) AS my_column 
    FROM
      mytable;
    

    Tested on SQLite 3.8.8.3, Thanks!

提交回复
热议问题