sqlite经典

经典sql语句:




5、将unix时间戳转化为日期格式

      select date(strftime('%s', '2012-07-20'), 'unixepoch')

4、将时间转化为unix时间戳格式,方便进行索引

       select strftime('%s', '2012-07-01');

3、将日期字段转换为当月:2012-07-01

       select date(f_字段, 'start of month') from   t_表;
       select   substr(f_字段, 1, 7 ) || '-01' as dd  ;


2、相当于mysql中的concat函数:
      select  f_id || '-01' from t_表;
      select   substr('2012-07-05', 1, 7 ) || '-01' as dd  ;

      ||相当于mysql中的concat,但谁都不会想到。


1、group_concat
       select   group_concat(f_id) from  t_表;

     注:某些版本比较低的PDO或者sqlite版本不支持此写法,但此写法效率挺高的。



快速导入导出(备份整个数据库):

       导出:sqlite.exe tt.sqlite3  ".dump" > dump_backup;
       导入:sqlite.exe tt.sqlite3  <  dump_backup;




错误相关:






1、bind or column index out of range
       这个错误可能出现在sql语句的绑定中使用了引号把绑定变量引起来,其实在sql语句中关于要绑定的变量是不需要引号的。
300*300
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.01114 秒