䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL AND/OR誊䞖严

PostgreSQL AND/OR誊䞖严

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

PostgreSQL䔇AND启OR誊䞖严䫘庯䂇劽崔婻溇傽準䚷償锬垔婔婻PostgreSQL臘婺䔇昄扞㔗認婴婻誊䞖严赆䓄婺誂毖臉誊䞖严㔗 gitbook.net

認底誊䞖严柊冕庖婔䓉䔇桹濘嘪彄崔婻婉劯䔇淉嘩严懫膄婘䕩劯䔇PostgreSQL臘㔗

www.gitbook.net

AND誊䞖严

AND誊䞖严噕螩庻婘崔婻溇傽婺䔇婔婻PostgreSQL臘婺䔇WHERE床埖㔗荘䇽嘪䫘AND誊䞖严垯昘䔇溇傽婋儖赆啺螆嘷欔橬䔇溇傽鄘潊䆋㔗冋套[溇傽1]启[溇傽2]儖婺true埻橬嘷認婴婻溇傽1启溇傽2鄘婺TRUE㔗

gitbook.net

臺濘

WHERE床埖䔇嘺橸臺濘婯淉嘩套婋 www.gitbook.net

SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN]; www.gitbook.net 

埇傖䂷劽嘪䫘AND誊䞖严溇傽N崔婻㔗庫麺埡PostgreSQL臺埖方螺垄滇婔婻庋媇潡昖臵欔橬彖䥂䔇溇傽媙釂滇TRUE㔗

www.gitbook.net

垂冋

蔄荏臘噸埩橬套婋螄嘘

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)
 
www.gitbook.net

幘醇崓庯潡京庯25幽婫噖蕇滇崓庯潡京庯65000.00欔橬䔇螄嘘婋麵SELECT臺埖彖臘

www.gitbook.net

testdb=# SELECT * FROM COMPANY WHERE AGE >= 25 AND SALARY >= 65000; 
gitbook.net

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

 id | name  | age | address    | salary
----+-------+-----+------------+--------
  4 | Mark  |  25 | Rich-Mond  |  65000
  5 | David |  27 | Texas      |  85000
(2 rows)
 
gitbook.net

OR誊䞖严:

OR誊䞖严幘埇䫘庯崔婻溇傽䂷劽蕙準婘婔婻PostgreSQL臘䔇WHERE床埖㔗荘䇽嘪䫘OR誊䞖严垯昘䔇溇傽婋儖赆啺螆傂嘘溇傽躿儏滇䩘垂䔇㔗冋套[溇傽1]潡[溇傽2]儖滇true套悩溇傽1潡溇傽2滇true㔗 www.gitbook.net

臺濘:

OR誊䞖严婯WHERE床埖䔇嘺橸臺濘套婋

gitbook.net

SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] OR [condition2]...OR [conditionN] 
gitbook.net

埇傖䂷劽N崔䔇溇傽婋嘪䫘OR誊䞖严㔗凹庯婔婻PostgreSQL臺埖方螺垄滇婔婻庋媇潡昖臵傂嘘婔婻彖䥂䔇溇傽潡滇TRUE㔗

gitbook.net

垂冋:

蔄荏噸埩臘婺橬傖婋螄嘘

gitbook.net

 # 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 

婋麵SELECT臺埖滇幘醇崓庯京庯25潡衻愘崓庯京庯65000.00欔橬䔇螄嘘彖臘 gitbook.net

testdb=# SELECT * FROM COMPANY WHERE AGE >= 25 OR SALARY >= 65000; 
gitbook.net

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

www.gitbook.net

 id | name  | age | address    | salary
----+-------+-----+------------+--------
  1 | Paul  |  32 | California |  20000
  2 | Allen |  25 | Texas      |  15000
  4 | Mark  |  25 | Rich-Mond  |  65000
  5 | David |  27 | Texas      |  85000
(4 rows) www.gitbook.net 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL AND/OR誊䞖严
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080558.html
婪婔䇺PostgreSQL WHERE臺埖      婋婔䇺PostgreSQL UPDATE昖臵