SQL语句汇总(方便粘贴sqlite语句)
作者:网络转载 发布时间:[ 2016/11/11 17:58:44 ] 推荐标签:SQL Server 数据库
DDL语句
删除表
DROP TABLE IF EXISTS 't_student';
创建表
CREATE TABLE IF NOT EXISTS 't_student' ( 'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'name' TEXT, 'age' INTEGER
);
DML语句
插入语句
INSERT INTO t_student (name, age) VALUES ('why', 18);
INSERT INTO t_student (name, age) VALUES ('lmj', 25);
INSERT INTO t_student (name, age) VALUES ('lnj', 22);
INSERT INTO t_student (name, age) VALUES ('yz', 17);
INSERT INTO t_student (name, age) VALUES ('wsz', 28);
更新数据
UPDATE t_student SET age = 30 WHERE name = 'why';
UPDATE t_student SET name = 'zs' WHERE age > 20;
删除数据
DELETE FROM t_student WHERE name = 'zs’;
DQL语句
基本查询
SELECT * FROM t_student;
查询特殊的字段
SELECT name, age FROM t_student;
通过条件来查询语句
SELECT name, age FROM t_student WHERE age <= 25;
通过条件查询(模糊查询)
SELECT name, age FROM t_student WHERE name LIKE '%l%';
多个条件的查询
SELECT name, age FROM t_student WHERE name LIKE '%l%' AND age >=25;
SELECT name, age FROM t_student WHERE name LIKE '%l%' OR age >=25;
计算个数
SELECT count(*) FROM t_student;
SELECT count(name) FROM t_student;
SELECT count(age) FROM t_student;
数据的排序
1> 升序 ASC(默认)
SELECT * FROM t_student ORDER BY age;
2> 降序
DESCSELECT * FROM t_student ORDER BY age DESC;
3> 以年龄的升序排序,如果年龄相同,以名字的降序排序
SELECT * FROM t_student ORDER BY age, name DESC;
起别名
1> 给表起别名
SELECT s.name, s.age FROM t_student AS s;
2> 给字段起别名
SELECT name AS myName, age AS myAge FROM t_student;
分页查询(limit)
1> 基本分
SELECT name, age FROM t_student LIMIT 4, 2;
2> 该语句的意思是:跳过0条数据,查询前五条数据
SELECT name, age FROM t_student LIMIT 5;
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11