SQLite具有许多内置函数,可对字符串或数字数据进行处理。
Sr.No. | Function & 描述 |
---|---|
1 | SQLite COUNT 函数 用于计算数据库表中的行数。 |
2 | SQLite MAX 函数 返回特定列选择最高(最大值)值。 |
3 | SQLite MIN 函数 返回特定列选择最低(最低)值。 |
4 | SQLite AVG 函数 返回某些表列的平均值。 |
5 | SQLite SUM 函数 返回列的总计值。 |
6 | SQLite RANDOM 函数 SQLite RANDOM函数返回-9223372036854775808和+9223372036854775807之间的伪随机整数。 |
7 | SQLite ABS 函数 返回数字参数的绝对值。 |
8 | SQLite UPPER 函数 将字符串转换为大写字母。 |
9 | SQLite LOWER 函数 将字符串转换为小写字母。 |
10 | SQLite LENGTH 函数 返回字符串的长度。 |
11 | SQLite sqlite_version 函数 返回SQLite库的版本。 |
在开始提供上述功能的示例之前,请考虑带有以下记录的COMPANY表。
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 1 Paul 32 California 20000.0 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 Learnfk 24 Houston 10000.0
SQLite COUNT聚合函数用于计算数据库表中的行数。
sqlite> SELECT count(*) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
count(*) ---------- 7
SQLite MAX聚合函数允许无涯教程为特定列选择最高(最大值)值。
sqlite> SELECT max(salary) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
max(salary) ----------- 85000.0
SQLite MIN聚合函数使无涯教程能够为特定列选择最低(最低)值。
sqlite> SELECT min(salary) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
min(salary) ----------- 10000.0
SQLite AVG聚合函数选择某个表列的平均值。
sqlite> SELECT avg(salary) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
avg(salary) ---------------- 37142.8571428572
SQLite SUM聚合函数允许为数字列选择总计。
sqlite> SELECT sum(salary) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
sum(salary) ----------- 260000.0
SQLite RANDOM函数返回-9223372036854775808和+9223372036854775807之间的伪随机整数。
sqlite> SELECT random() AS Random;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
Random ------------------- 5876796417670984050
SQLite ABS函数返回数字参数的绝对值。
sqlite> SELECT abs(5), abs(-15), abs(NULL), abs(0), abs("ABC");
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
abs(5) abs(-15) abs(NULL) abs(0) abs("ABC") ---------- ---------- ---------- ---------- ---------- 5 15 0 0.0
SQLite UPPER函数将字符串转换为大写字母。
sqlite> SELECT upper(name) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
upper(name) ----------- PAUL ALLEN TEDDY MARK DAVID KIM JAMES
SQLite LOWER函数将字符串转换为小写字母。
sqlite> SELECT lower(name) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
lower(name) ----------- paul allen teddy mark david kim james
SQLite LENGTH函数返回字符串的长度。
sqlite> SELECT name, length(name) FROM COMPANY;
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
NAME length(name) ---------- ------------ Paul 4 Allen 5 Teddy 5 Mark 4 David 5 Kim 3 Learnfk 5
SQLite sqlite_version函数返回SQLite库的版本。
sqlite> SELECT sqlite_version() AS 'SQLite Version';
上面的SQLite SQL语句将产生以下内容。
链接:https://www.learnfk.comhttps://www.learnfk.com/sqlite/sqlite-useful-functions.html
来源:LearnFk无涯教程网
SQLite Version -------------- 3.6.20
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)