扫码一下
查看教程更方便
表达式是一个或多个值、运算符和计算值的sql函数的组合。
sql 表达式与公式类似,都写在查询语言中。您还可以使用特定的数据集来查询数据库。
假设 select 语句的基本语法如下:
select column1, column2, columnn
from table_name
where [condition | expression];
有不同类型的 sqlite 表达式,具体讲解如下:
sqlite 的布尔表达式在匹配单个值的基础上获取数据。语法如下:
select column1, column2, columnn
from table_name
where single value matching expression;
假设 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 james 24 houston 10000.0
下面的示例演示了 sqlite 布尔表达式的用法:
sqlite> select * from company where salary = 10000;
id name age address salary
---------- ---------- ---------- ---------- ----------
4 james 24 houston 10000.0
这些表达式用来执行查询中的任何数学运算。语法如下:
select numerical_expression as operation_name
[from table_name where condition] ;
在这里,numerical_expression 用于数学表达式或任何公式。下面的实例演示了 sqlite 数值表达式的用法:
sqlite> select (15 6) as addition
addition = 21
有几个内置的函数,比如 avg()、sum()、count(),等等,执行被称为对一个表或一个特定的表列的汇总数据计算。
sqlite> select count(*) as "records" from company;
records = 7
日期表达式返回当前系统日期和时间值,这些表达式将被用于各种数据操作。
sqlite> select current_timestamp;
current_timestamp = 2013-03-17 10:43:35