PostgreSQL表达式
语法:
考虑SELECT语句的基本语法如下:
SELECT column1, column2, columnN FROM table_name WHERE [CONTION | EXPRESSION];
PostgreSQL表达式,这是下面提到的不同类型的:
PostgreSQL布尔表达式:
PostgreSQL的布尔表达式匹配的单个值的基础上取数据。以下是语法:
SELECT column1, column2, columnN FROM table_name WHERE SINGLE VALUE MATCHTING EXPRESSION;
考虑表COMPANY有如下记录:
testdb# select * from COMPANY; id | name | age | address | salary ----+-------+-----+-----------+-------- 1 | Paul | 32 | California| 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall| 45000 7 | James | 24 | Houston | 10000 (7 rows)
下面是一个简单的例子显示使用PostgreSQL的布尔表达式:
testdb=# SELECT * FROM COMPANY WHERE SALARY = 10000;
以上PostgreSQL的语句会产生以下结果:
id | name | age | address | salary ---+-------+-----+----------+-------- 7 | James | 24 | Houston | 10000 1 row)
PostgreSQL - 数字表达式:
这些表达式用来执行任何数学运算的任何查询。以下是语法:
SELECT numerical_expression as OPERATION_NAME [FROM table_name WHERE CONDITION] ;
这里数值表达式是用于数学表达式或任何公式。下面是一个简单的例子显示使用SQL数值表达式:
testdb=# SELECT (15 + 6) AS ADDITION ;
以上PostgreSQL表达式会产生以下结果:
addition ---------- 21 (1 row)
There are several built-in functions like avg(), sum(), count() etc to perform what is known as aggregate data calculations against a table or a specific table column.
testdb=# SELECT COUNT(*) AS "RECORDS" FROM COMPANY;
以上PostgreSQL的表会产生以下结果:
RECORDS --------- 7 (1 row)
PostgreSQL日期表达式:
日期表达式返回当前系统日期和时间值,这些表达式将被用于各种数据操作。
testdb=# SELECT CURRENT_TIMESTAMP;
以上PostgreSQL的表会产生以下结果:
相关推荐
WanKaShing 2020-11-12
zhbvictor 2020-10-29
kls00 2020-10-15
89921334 2020-07-29
83911930 2020-07-28
89407707 2020-06-27
89921334 2020-06-26
89244553 2020-06-21
84593973 2020-06-21
83911930 2020-06-16
yaoding 2020-06-14
89244553 2020-06-11
89407707 2020-06-11
89921334 2020-06-10
89407707 2020-06-10
goodriver 2020-06-09
kevinli 2020-06-06
84593973 2020-06-05