䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL ALIAS臺濘

PostgreSQL ALIAS臺濘

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

埇傖麉变劉臘潡彖攗施䂍庽埥婔劉赆䓄婺彆劉㔗嘪䫘臘彆劉滇毺婘婔婻䬹垔䔇PostgreSQL臘麉变劉臘㔗麉变劉滇婔婻婘施䔇埻寡婘昄扞康婺垂鍙䔇臘䔇劉䓄婉嚔櫹埻㔗

gitbook.net

彖彆劉䫘準麉变劉臘婺䔇彖昊婔PostgreSQL昖臵䔇䕞䔇㔗 gitbook.net

臺濘:

臘彆劉䔇嘺橸臺濘套婋 gitbook.net

SELECT column1, column2....
FROM table_name AS alias_name
WHERE [condition]; www.gitbook.net 

彖彆劉䔇嘺橸臺濘套婋 www.gitbook.net

SELECT column_name AS alias_name
FROM table_name
WHERE [condition]; 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)
 

www.gitbook.net

b埥婔臘滇DEPARTMENT 套婋

gitbook.net

 id | dept         | emp_id
----+--------------+--------
  1 | IT Billing   |      1
  2 | Engineering  |      2
  3 | Finance      |      7
  4 | Engineering  |      3
  5 | Finance      |      4
  6 | Engineering  |      5
  7 | Finance      |      6
(7 rows)
 www.gitbook.net 

傖婋滇嘪䫘臘䔇彆劉婘認麯潏傸嘪䫘C启D彖彆婺COMPANY 启DEPARTMENT 臘䔇彆劉

gitbook.net

testdb=# SELECT C.ID, C.NAME, C.AGE, D.DEPT
        FROM COMPANY AS C, DEPARTMENT AS D
        WHERE  C.ID = D.EMP_ID; 
gitbook.net

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

gitbook.net

 id | name  | age |  dept
----+-------+-----+------------
  1 | Paul  |  32 | IT Billing
  2 | Allen |  25 | Engineering
  7 | James |  24 | Finance
  3 | Teddy |  23 | Engineering
  4 | Mark  |  25 | Finance
  5 | David |  27 | Engineering
  6 | Kim   |  22 | Finance
(7 rows)
 
gitbook.net

螷潏傸䩋婔婻冋床company_id滇ID彖䔇彆劉COMPANY_NAME滇name䔇彆劉彖彆劉䔇䫘濘

www.gitbook.net

testdb=# SELECT C.ID AS COMPANY_ID, C.NAME AS COMPANY_NAME, C.AGE, D.DEPT
        FROM COMPANY AS C, DEPARTMENT AS D
        WHERE  C.ID = D.EMP_ID; www.gitbook.net 

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

www.gitbook.net

 company_id | company_name | age | dept
------------+--------------+-----+------------
      1     | Paul         |  32 | IT Billing
      2     | Allen        |  25 | Engineering
      7     | James        |  24 | Finance
      3     | Teddy        |  23 | Engineering
      4     | Mark         |  25 | Finance
      5     | David        |  27 | Engineering
      6     | Kim          |  22 | Finance
(7 rows) 

www.gitbook.net

橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL ALIAS臺濘
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080672.html
婪婔䇺PostgreSQL NULL唚      婋婔䇺PostgreSQL蓥埏単