HiveQL命令行的使用

實驗步驟

注意:由于數據庫對大小寫不敏感,因此大寫和小寫都可以使用。

1. HiveQL:數據操作

(1)進入HiveQL,命令如下:

hive

image

(2)Hive創建數據庫:創建一個名為userdb的數據庫

命令:

create database userdb;

image

隨時可以通過show命令來查看Hive中所包含的數據庫:

命令:

show databases;

image

Hive會為每個數據庫創建一個目錄。數據庫中的表將會以這個數據庫目錄的子目錄形式存儲。

(3)Hive創建表

首先需要使用use命令使用數據庫userdb:

use userdb;

image

再根據相應要求在userdb數據庫中創建表(僅僅是創建表結構,表中并沒有內容):

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n60" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

create table if not exists employee ( id int, name String, salary String, designation String)

comment 'employee1 details'

row format delimited

fields terminated BY '\t'

lines terminated BY '\n'

stored as textfile;

</pre>

image

(4)Hive加載數據:向建的表employee中加載數據

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n65" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

load data local inpath '/opt/sample.txt'

overwrite into table employee;

</pre>

image

(5)查看數據是否加載成功

select * from employee;

image

(5)Hive修改表

①. 重命名表,將表名由employee修改為emp

alter table employee rename to emp;

image

查看名稱是否正確修改:

show tables;

image

②. 刪除表emp

drop table emp;

image

查看是否刪除成功:

show tables;

image

(6)刪除數據庫

①. 若刪除的數據庫不為空則會報錯。如下圖所示:

drop database if exists userdb1;

image

②. 若刪除的數據庫為空則可以成功刪除,如下圖所示:

drop database if exists userdb;

image

此時,再查看數據庫則會看到userdb1沒有被刪除,而userdb已被刪除。

show databases;

image

(7)使用數據庫userdb1,接下來所有操作均在此數據庫中執行。

use userdb1;

image

(8)Hive分區

我們已經有一張分區表,名為employee1,下面為這張表添加分區。

①. 添加分區

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n132" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

alter table employee1

add partition (year='2012') location '/opt/empdata/2012/part2012.txt'

partition (year='2013') location '/opt/empdata/2013/part2013.txt';

</pre>

image

②. 查看分區:

show partitions employee1;

image

③. 寫入數據:

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n143" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

load data local inpath '/opt/empdata/2013/file3'

into table employee1 partition(year='2013');

load data local inpath '/opt/empdata/2012/file2'

into table employee1 partition(year='2012');

</pre>

image

(9)導出數據

①. 將表employee1中的數據導出到HDFS

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n150" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

insert overwrite directory '/home/Test/hdfs'

row format delimited

fields terminated by '\t'

select * from employee1;

</pre>

image

查看(注意:在集群中查看,需要先退出hiveQL,輸入quit;命令來退出數據庫到root用戶下執行查詢命令)

hadoop fs -cat /home/Test/hdfs/000000_0

image

②. 將表employee1中的數據導出到本地文件系統(注意:在HiveQL中操作,需要先進入hiveQL,輸入命令hive。每次重新進入hiveQL都要使用“use userdb1;”命令來指定需要操作的數據庫。)

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n161" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

insert overwrite local directory '/home/Test/sample'

row format delimited

fields terminated by '\t'

select * from employee1;

</pre>

image

查看(注意:在集群中查看,需要先退出hiveQL,輸入quit;命令來退出數據庫到root用戶下執行查詢命令)

cat /home/Test/sample/000000_0

image

③. 將表employee1中的數據導出到已經存在的表employee2(注意:在HiveQL中操作,需要先進入hiveQL,輸入命令hive。每次重新進入hiveQL都要使用“use userdb1;”命令來指定需要操作的數據庫。)

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n172" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

insert into table employee2

select * from employee1;

</pre>

image

查看數據是否導入到表employee2中:

select * from employee2;

image

④. 給分區重命名,并且查看重命名是否成功:

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n182" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

alter table employee1 partition (year='2013')

rename to partition (year='2014');

</pre>

image

show partitions employee1;

image

⑤. 刪除分區,并且查看分區是否刪除成功:

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n191" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

alter table employee1 drop

partition (year='2014');

</pre>

image

show partitions employee1;

[圖片上傳中...(image-78082e-1509677357636-21)]

(10)外部表的基本操作

①. 創建外部表,表名為exter_emp:

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n202" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

create external table exter_emp( id int, name String, age int, tel String)

row format delimited

fields terminated by '\t'

lines terminated by '\n'

stored as textfile

location '/home/Test/External';

</pre>

[圖片上傳中...(image-c08f8d-1509677357636-20)]

②. 向外部表中加載數據:

load data local inpath '/opt/empdata/file4' into table exter_emp;

image

③. 查看表中是否成功導入數據:

select * from exter_emp;

image

④. 刪除外部表exter_emp:

drop table exter_emp;

image

⑤. 查看文件本體依然存在:刪除外部表的時候,Hive僅僅刪除外部表的元數據,數據是不會刪除的。

dfs -ls /home/Test/External;

image

2. HiveQL查詢操作

(1)創建外部表employees

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n232" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

create external table employees(eid int,name String,salary float,age int,birthday date,

subordinates array<String>,

deductions map<String,float>,

address struct<street:String,city:String,state:String>)

row format delimited

fields terminated by '\t'

collection items terminated by ','

map keys terminated by ':'

location '/home/Test/external-1';

</pre>

image

向外部表employees中加載數據:

load data local inpath '/opt/empdata/file5' into table employees;

image

(2)SELECT...FROM語句的使用

①. 查看employees表中的薪水數據

select name,salary from employees;

image

②. 查看employees表中的下屬數據信息

select name,subordinates from employees;

image

③. 查看employees表中的扣除稅數據

select name,deductions from employees;

image

④. 引用復合字段查看下級數據

select name,subordinates[0] from employees;

image

⑤. 選擇一個deductions元素進行查詢

select name,deductions["FedTax"] from employees;

image

(3)使用列值計算

①. 把查詢得到的員工姓名轉換為大寫并計算員工的稅后薪資

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n277" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

select upper(name),salary,deductions["FedTax"],

round(salary*(1-deductions["FedTax"])) from employees;

</pre>

image

②. 內置函數查詢表employees中有多少員工,以及計算員工平均薪水

select count(*),avg(salary) from employees;

image

③. 將employees表中每行記錄中的subordinates字段內容轉換成0個或者多個新的記錄行。如果某行員工記錄subordinates字段內容為空的話,就不會產生記錄;如果不為空,那么這個數組的每個元素都將產生一行新記錄:

select explode(subordinates) as sub from employees;

image

(4)SELECT...WHERE語句的使用

查看薪資超過30000的員工

select * from employees2 where salary > 30000;

image

(5)GROUP BY 語句的使用

查詢獲取每個部門的員工人數的查詢語句如下:

?

select dept,count(*) from employees2 group by dept;

image

(6)ORDER BY語句的使用

獲取員工的詳細信息,并把結果按照部門名稱排序:

select id,name, dept from employees2 order by dept;

image

(7)JOIN語句的使用

①. 下面的查詢對customers和orders進行連接,找出每個客戶下的訂單信息。連接的條件是customers表中的id必須與orders表中的customer_id相同。這個JOIN操作實際上就是獲取每個下了訂單的客戶的訂單情況。如果某個客戶沒有下過任何訂單,那么該客戶的信息將不會返回。

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n320" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

select c.id, c.name, c.age, o.amount

from customers c join orders o

on (c.id = o.customer_id);

image

②. HiveQL LEFT OUTER JOIN(左外連接)返回所有行左表,即使是在右邊的表中沒有匹配。這意味著,如果ON子句匹配的右表0(零)記錄,JOIN還是返回結果行,但在右表中的每一列的值為NULL。這個LEFT OUTER JOIN操作實際上就是獲取每個客戶的訂單情況,不管客戶是不是下過訂單,該客戶的信息都將會返回。通過這個操作,用戶可以了解到整個客戶的情況,包括下過訂單的客戶和沒有下過訂單的客戶。

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n325" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

select c.id, c.name, o.amount, o.time

from customers c

left outer join orders o

on (c.id = o.customer_id);

image

③. HiveQL RIGHT OUTER JOIN(右外連接)返回右邊表的所有行,即使在左表中沒有匹配。如果ON子句的左表匹配0(零)的記錄,JOIN結果返回一行,但在左表中的每一列為NULL。這個RIGHT OUTER JOIN操作實際上就是獲取所有訂單的訂單和下單客戶的情況,即使某個訂單沒有下單客戶ID,也會返回該訂單的情況,有關客戶信息項將為NULL.

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n330" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

select c.id, c.name, o.amount, o.time

from customers c

right outer join orders o

on (c.id = o.customer_id);

image

④. HiveQL FULL OUTER JOIN(完全外連接)將會返回兩個表的所有記錄。如果任一表的指定字段沒有符合條件的值的話,那么就使用NULL值替代。這個FULL OUTER JOIN操作實際上就是首先進行LEFT OUTER JOIN,再進行RIGHT OUTER JOIN。也就是說,首先獲取所有客戶的訂單信息,如果沒有訂單,相應的訂單信息項就返回NULL;然后再獲取所有訂單的客戶信息,如果沒有客戶,那么有關客戶信息項將為NULL。

<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n335" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; display: block; break-inside: avoid; text-align: left; background-image: ; background-position: var(--code-block-bg-color); background-size: ; background-repeat: var(--code-block-bg-color); background-attachment: ; background-origin: ; background-clip: ; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(221, 221, 221); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

select c.id, c.name, o.amount, o.time

from customers c

full outer join orders o

on (c.id = o.customer_id);

</pre>


image
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,156評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,401評論 3 415
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,069評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,873評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,635評論 6 408
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,128評論 1 323
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,203評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,365評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,881評論 1 334
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,733評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,935評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,475評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,172評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,582評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,821評論 1 282
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,595評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,908評論 2 372

推薦閱讀更多精彩內容