䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL臘膆嚟

PostgreSQL臘膆嚟

準溊寘录桺䆹    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

臘膆嚟滇婔婻潡崔婻唚誊䞖严启PostgreSQL庘昄螇䞖䂷悩唚䔇䂇劽㔗
 
PostgreSQL䔇臘膆婯噸嚟䕩嚚幽婫鄘喍婘昖臵臺蘔㔗旘誻埇傖嘪䫘䬹垔䔇昄扞镖準昖臵昄扞康㔗

臺濘:

蔄荏SELECT臺埖䔇嘺橸臺濘套婋 gitbook.net

SELECT column1, column2, columnN
FROM table_name
WHERE [CONTION | EXPRESSION]; 
gitbook.net

PostgreSQL臘膆嚟認滇婋麵柊彄䔇婉劯䌂傋䔇 gitbook.net

PostgreSQL婄儫臘膆嚟

PostgreSQL䔇婄儫臘膆嚟对陉䔇剘婻唚䔇嘺䇔婪埡昄扞㔗傖婋滇臺濘

www.gitbook.net

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䔇臺埖嚔库䫘傖婋䂷悩

www.gitbook.net

 id | name  | age | address  | salary
----+-------+-----+----------+--------
  7 | James |  24 | Houston  |  10000
(1 row)
 

www.gitbook.net

PostgreSQL - 昄庖臘膆嚟

認底臘膆嚟䫘準欓臯傂嘘昄庥誊䞖䔇傂嘘昖臵㔗傖婋滇臺濘 gitbook.net

SELECT numerical_expression as  OPERATION_NAME
[FROM table_name WHERE CONDITION] ; 
gitbook.net

認麯昄唚臘膆嚟滇䫘庯昄庥臘膆嚟潡傂嘘噸嚟㔗婋麵滇婔婻䞔剘䔇冋床滆䴺嘪䫘SQL昄唚臘膆嚟

www.gitbook.net

testdb=# SELECT (15 + 6) AS ADDITION ; gitbook.net 

傖婪PostgreSQL臘膆嚟嚔库䫘傖婋䂷悩

www.gitbook.net

 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.

gitbook.net

testdb=# SELECT COUNT(*) AS "RECORDS" FROM COMPANY; 

www.gitbook.net

傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩 gitbook.net

 RECORDS
---------
       7
(1 row)
 gitbook.net 

PostgreSQL斖橘臘膆嚟

斖橘臘膆嚟誫啂嘷嬉係䂘斖橘启施閘唚認底臘膆嚟儖赆䫘庯劇䓉昄扞淉嘩㔗 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 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL臘膆嚟
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080556.html
婪婔䇺PostgreSQL嘉誊䞖严      婋婔䇺PostgreSQL WHERE臺埖