Sqlite基础

数据库文件*.sqlite

使用方法 sqlite3 database.sqlite

*.sql执行语句

使用方法sqlite3 database.sqlite < sampl.sql

1
2
3
#sampl.sql
.tables
SELECT * FROM talbe1;

创建数据库CREATE TABLE tname (var1 char[1],var2 char[1]);

参数类型 char[5],int,float

从其他表插入INSET INTO t1 SELECT var1,var2 FROM t2;

将表t2中var1 vat2插入表t1

删除表DROP TABLE tname;

匹配两个字段合并GROUP BY var1, var2

表内连外连FROM t1 INNER JOIN t2 ON t1.v=t2.v;

其他连接INNER/LEFT/RIGHT JOIN

1
2
SELET * FROM t1 INNER JOIN t2 ON t1.id = t2.id;
SELET * FROM t1 INNER JOIN t2 ON t1.id = t2.id WHERE id<100;

统计COUNT()

返回一行SELECT COUNT(*) FROM t1;

(不合并)统计相同id有多少行 SELECT COUNT(DISTINCT id) FROM t1;

(合并)统计相同id有多少行SELECT COUNT(*) GROUP BY id FROM t1;


转载请注明来源 https://tianweiye.github.io