赞
踩
步骤:
1、使用sqlite3命令进入sqlite终端:sqlite3 test.db
2、.output test.sql
3、.dump
4、退出sqlite终端,ls,即可发现目录下多出了一个test.sql文件,这个文件即为备份的数据库
5、然后再从这个文件导入到数据库,首先新建一个文件:touch test1.db,这个文件即为sqlite数据库
6、使用sqlite3命令进入这个数据库:sqlite3 test1.db
7、.read test.sql
通过以上步骤即可从test.db复制出一个test1.db数据库来
场景二:需要备份或修改某个表:
步骤:
1、使用sqlite3命令进入sqlite终端:sqlite3 test.db
2、.output test.sql
3、select * from table1;
4、退出sqlite终端,ls,即可发现目录下多出了一个test.sql文件,这个文件即为备份的数据
5、然后再从这个文件导入数据,使用sqlite3命令进入这个数据库:sqlite3 test1.db
7、.import test.sql table1
通过以上步骤即可从test.db中备份某个表数据
场景三:分类查询
假设有这样一张表,统计每个用户每天的登录次数userinfo:
username time type count
张三 4号 1 5
张三 6号 3 4
张三 11号 1 11
李四 11号 1 9
其中type表示星期几,count表示该天的登录次数,
比如第一条表示张三在4号(星期一)登录了5次,
如果我们要计算某个用户各个工作日的登录次数,可以用如下一条语句:
- select sum(case when type=0 then count else 0 end) as sum_sunday,
-
- sum(case when type=1 then count else 0 end) as sum_monday,
-
- ...
-
- from userinfo where username='张三';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。