PostgreSQL 比较运算符
考虑下面的表 公司 其记录如下−
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)
以下是使用PostgresSQL比较操作符的简单示例。
在这里,我们使用了 WHERE 子句,该子句将在单独的章节中解释,但目前您可以理解WHERE子句用于在SELECT语句中加入条件语句。
以下SELECT语句列出了所有工资大于50,000.00的记录 –
testdb=# SELECT * FROM COMPANY WHERE SALARY > 50000;
以上提供的PostgreSQL语句将生成以下结果 –
id | name | age |address | salary
----+-------+-----+-----------+--------
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
(2 rows)
下面的SELECT语句列出了所有工资为20,000.00的记录−
testdb=# SELECT * FROM COMPANY WHERE SALARY = 20000;
给定的PostgreSQL语句将产生以下结果−
id | name | age | address | salary
----+-------+-----+-------------+--------
1 | Paul | 32 | California | 20000
3 | Teddy | 23 | Norway | 20000
(2 rows)
下面的SELECT语句列出了所有工资不等于20,000.00的记录 −
testdb=# SELECT * FROM COMPANY WHERE SALARY != 20000;
给定的PostgreSQL语句将产生如下结果−
id | name | age | address | salary
----+-------+-----+-------------+--------
2 | Allen | 25 | Texas | 15000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
(5 rows)
以下SELECT语句列出所有薪资不等于20,000.00的记录−
testdb=# SELECT * FROM COMPANY WHERE SALARY <> 20000;
给定的PostgreSQL语句将产生以下结果 –
id | name | age | address | salary
----+-------+-----+------------+--------
2 | Allen | 25 | Texas | 15000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
(5 rows)
下面的SELECT语句列出了所有薪水大于或等于65,000.00的记录−
testdb=# SELECT * FROM COMPANY WHERE SALARY >= 65000;
上述给出的PostgreSQL语句将产生以下结果−
id | name | age | address | salary
----+-------+-----+-----------+--------
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
(2 rows)