埇傖麉变劉臘潡彖攗施䂍庽埥婔劉赆䓄婺彆劉㔗嘪䫘臘彆劉滇毺婘婔婻䬹垔䔇PostgreSQL臘麉变劉臘㔗麉变劉滇婔婻婘施䔇埻寡婘昄扞康婺垂鍙䔇臘䔇劉䓄婉嚔櫹埻㔗
彖彆劉䫘準麉变劉臘婺䔇彖昊婔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 臘套婋
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䔇彆劉彖彆劉䔇䫘濘
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䔇臘嚔库䫘傖婋䂷悩
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