PostgreSQL比較操作符
考慮一下表 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 | gitbook.net | 24 | Houston2 | 10000 (7 rows)
下麵是簡單的例子,顯示使用PostgreSQL比較操作符:
在這裡,我們已經使用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)