蔄荏SELECT臺埖䔇嘺橸臺濘套婋 gitbook.net
SELECT column1, column2, columnN FROM table_name WHERE [CONTION | EXPRESSION];gitbook.net
PostgreSQL臘膆嚟認滇婋麵柊彄䔇婉劯䌂傋䔇 gitbook.net
PostgreSQL䔇婄儫臘膆嚟对陉䔇剘婻唚䔇嘺䇔婪埡昄扞㔗傖婋滇臺濘
SELECT column1, column2, columnN FROM table_name WHERE SINGLE VALUE MATCHTING EXPRESSION;www.gitbook.net
蔄荏臘 COMPANY橬套婋螄嘘 www.gitbook.net
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) gitbook.net
婋麵滇婔婻䞔剘䔇冋床滆䴺嘪䫘PostgreSQL䔇婄儫臘膆嚟 gitbook.net
testdb=# SELECT * FROM COMPANY WHERE SALARY = 10000; gitbook.net
傖婪PostgreSQL䔇臺埖嚔库䫘傖婋䂷悩
id | name | age | address | salary ----+-------+-----+----------+-------- 7 | James | 24 | Houston | 10000 (1 row)www.gitbook.net
認底臘膆嚟䫘準欓臯傂嘘昄庥誊䞖䔇傂嘘昖臵㔗傖婋滇臺濘 gitbook.net
SELECT numerical_expression as OPERATION_NAME [FROM table_name WHERE CONDITION] ;gitbook.net
認麯昄唚臘膆嚟滇䫘庯昄庥臘膆嚟潡傂嘘噸嚟㔗婋麵滇婔婻䞔剘䔇冋床滆䴺嘪䫘SQL昄唚臘膆嚟
testdb=# SELECT (15 + 6) AS ADDITION ; gitbook.net
傖婪PostgreSQL臘膆嚟嚔库䫘傖婋䂷悩
addition ---------- 21 (1 row) www.gitbook.net
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;www.gitbook.net
傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 gitbook.net
RECORDS --------- 7 (1 row) gitbook.net
斖橘臘膆嚟誫啂嘷嬉係䂘斖橘启施閘唚認底臘膆嚟儖赆䫘庯劇䓉昄扞淉嘩㔗 www.gitbook.net
testdb=# SELECT CURRENT_TIMESTAMP; www.gitbook.net
傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 gitbook.net
now
-------------------------------
2013-05-06 14:38:28.078+05:30
(1 row) gitbook.net