<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cosmos DB &#8211; 科技島-掌握科技新聞、科技職場最新資訊</title>
	<atom:link href="https://www.technice.com.tw/tag/cosmos-db/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.technice.com.tw</link>
	<description>專注於科技新聞、科技職場、科技知識相關資訊，包含生成式AI、人工智慧、Web 3.0、區塊鏈、科技職缺百科、生物科技、軟體發展、雲端技術等豐富內容，適合熱衷科技及從事科技專業人事第一手資訊的平台。</description>
	<lastBuildDate>Thu, 10 Sep 2026 08:51:10 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.2</generator>

<image>
	<url>https://www.technice.com.tw/wp-content/uploads/2022/12/cropped-wordpress_512x512-150x150.png</url>
	<title>Cosmos DB &#8211; 科技島-掌握科技新聞、科技職場最新資訊</title>
	<link>https://www.technice.com.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>讓 Cosmos DB 的資料開口說話：從等分析師，到自然語言查詢｜專家論點【黃婉中】</title>
		<link>https://www.technice.com.tw/opinion/274103/</link>
					<comments>https://www.technice.com.tw/opinion/274103/#respond</comments>
		
		<dc:creator><![CDATA[林育如]]></dc:creator>
		<pubDate>Wed, 09 Sep 2026 01:00:36 +0000</pubDate>
				<category><![CDATA[專家論點]]></category>
		<category><![CDATA[Cosmos DB]]></category>
		<category><![CDATA[自然語言]]></category>
		<category><![CDATA[黃婉中]]></category>
		<guid isPermaLink="false">https://www.technice.com.tw/?p=274103</guid>

					<description><![CDATA[<p><img width="1393" height="756" src="https://www.technice.com.tw/wp-content/uploads/2026/09/h1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="讓 Cosmos DB 的資料開口說話：從等分析師，到自然語言查詢。（圖／AI生成）" decoding="async" srcset="https://www.technice.com.tw/wp-content/uploads/2026/09/h1.jpg 1393w, https://www.technice.com.tw/wp-content/uploads/2026/09/h1-300x163.jpg 300w, https://www.technice.com.tw/wp-content/uploads/2026/09/h1-1024x556.jpg 1024w, https://www.technice.com.tw/wp-content/uploads/2026/09/h1-768x417.jpg 768w" sizes="(max-width: 1393px) 100vw, 1393px" title="讓 Cosmos DB 的資料開口說話：從等分析師，到自然語言查詢｜專家論點【黃婉中】 1"></p>
<p>有個貸款客戶想要回答一些商業問題，例如「這個月哪個合作機構的成交量最高」。他們本來是用 Cosmos DB 存資料，但每次想知道這類問題的答案，都得找分析師，寫一段查詢、等結果。為了縮短等待，我們幫他們把資料攤平、做反正規化，讓客戶從此可以直接用自然語言去查詢，不用再等分析師。<content>作者：黃婉中（雲端架構師）</p>
<p><span style="font-weight: 400;">有個貸款客戶想要回答一些商業問題，例如「這個月哪個合作機構的成交量最高」。他們本來是用 Cosmos DB 存資料，但每次想知道這類問題的答案，都得找分析師，寫一段查詢、等結果。為了縮短等待，我們幫他們把資料攤平、做反正規化，讓客戶從此可以直接用自然語言去查詢，不用再等分析師。</span></p>
<p>[caption id="attachment_274110" align="alignnone" width="885"]<img class=" wp-image-274110" src="https://www.technice.com.tw/wp-content/uploads/2026/09/h1-300x163.jpg" alt="讓 Cosmos DB 的資料開口說話：從等分析師，到自然語言查詢。（圖／AI生成）" width="885" height="481" /> （圖／AI生成）[/caption]</p>
<p><span style="font-weight: 400;">這篇想把中間比較細節的兩個部分拆開來講：一是為什麼 Cosmos DB 不適合直接分析，二是攤平跟反正規化在做什麼。</span></p>
<h2><b>資料庫的兩種個性：OLTP 跟 OLAP</b></h2>
<p><span style="font-weight: 400;">先講兩個詞，因為後面會一直用到。</span></p>
<p><b>OLTP</b><span style="font-weight: 400;">（Online Transaction Processing，線上交易處理）：例如打給客服、銀行轉帳。OLTP 資料庫的強項是「單一一筆」存取。</span></p>
<p><b>OLAP</b><span style="font-weight: 400;">（Online Analytical Processing，線上分析處理）：例如「這個月哪個放款機構成交最多」。OLAP 資料庫的強項是「大量資料」統計。</span></p>
<p data-start="255" data-end="377">「AI履歷健檢」看見自己優勢：<span style="color: #33cccc;"><a style="color: #33cccc;" href="https://campaign.1111.com.tw/resume-review/" target="_blank" rel="noopener"><strong>https://campaign.1111.com.tw/resume-review/</strong></a></span></p>
<p data-start="255" data-end="377">更多科技工作請上科技專區：<span style="color: #33cccc;"><a style="color: #33cccc;" href="https://techplus.1111.com.tw/" target="_blank" rel="noopener"><strong>https://techplus.1111.com.tw/</strong></a></span></p>
<h2><b>Cosmos DB 是 OLTP，但跟 SQL 的 OLTP 不一樣</b></h2>
<p><span style="font-weight: 400;">這裡有個容易搞混的地方：傳統 SQL 資料庫也是拿來做 OLTP 的，但它跟 Cosmos DB 做 OLTP 的方式不一樣。</span></p>
<p><b>SQL 資料庫：把資料拆細（正規化）。</b><span style="font-weight: 400;"> 客戶資料一張表、貸款資料一張表、還款紀錄一張表，彼此用關聯串起來。這樣做的好處是，如果客戶改名字，只要改一個地方，不會有些表改了、有些表忘記改，資料不會兜不起來。查詢的時候，用 JOIN 把幾張表接起來看。</span></p>
<p><b>Cosmos DB：把資料打包在一起。</b><span style="font-weight: 400;"> 一個客戶的姓名、聯絡方式、名下所有貸款、每筆貸款的還款紀錄，全部塞進同一份 JSON 文件裡。客服系統一查這個客戶，一次就把所有相關資料抓齊，不用像 SQL 那樣東拼西湊做 JOIN，速度極快。</span></p>
<p><span style="font-weight: 400;">這也是為什麼 Cosmos DB 裡的資料長得「一層包一層」，技術上叫</span><b>巢狀結構</b><span style="font-weight: 400;">（nested structure），客戶底下包貸款，貸款底下包還款紀錄，像俄羅斯娃娃一樣。是為了讓應用程式查詢快的刻意設計。</span></p>
<p><span style="font-weight: 400;">兩個產品都是為了讓「單筆存取」快，只是方法不同。</span></p>
<h2><b>想做分析，才發現這個設計不夠用</b></h2>
<p><span style="font-weight: 400;">當資料累積多了，客戶開始想要做分析，回答「這個月哪個放款機構成交最多」。像這種要攤開所有客戶、所有貸款，跨資料去加總比較，是巢狀打包結構最不擅長的事。因為資料被鎖在一份一份的文件裡，每份都要打開來看，才能湊出跨資料的統計結果。</span></p>
<h2><b>解法：「反正規化」把資料變成一張寬表</b></h2>
<p><span style="font-weight: 400;">要解決這個問題，做法是把巢狀資料攤平成表格。</span></p>
<p><span style="font-weight: 400;">用一個具體例子說明。一間店有兩個客戶：小明住台北，買過兩次東西；小華住高雄，買過一次。</span></p>
<p><span style="font-weight: 400;">如果是 SQL 正規化的做法，會拆成三張小表：</span></p>
<p><b>客戶表</b></p>
<table>
<tbody>
<tr>
<td><b>客戶編號</b></td>
<td><b>姓名</b></td>
<td><b>城市</b></td>
</tr>
<tr>
<td><span style="font-weight: 400;">C001</span></td>
<td><span style="font-weight: 400;">小明</span></td>
<td><span style="font-weight: 400;">台北</span></td>
</tr>
<tr>
<td><span style="font-weight: 400;">C002</span></td>
<td><span style="font-weight: 400;">小華</span></td>
<td><span style="font-weight: 400;">高雄</span></td>
</tr>
</tbody>
</table>
<p><b>產品表</b></p>
<table>
<tbody>
<tr>
<td><b>產品編號</b></td>
<td><b>產品名稱</b></td>
<td><b>單價</b></td>
</tr>
<tr>
<td><span style="font-weight: 400;">P01</span></td>
<td><span style="font-weight: 400;">鍵盤</span></td>
<td><span style="font-weight: 400;">100</span></td>
</tr>
<tr>
<td><span style="font-weight: 400;">P02</span></td>
<td><span style="font-weight: 400;">滑鼠</span></td>
<td><span style="font-weight: 400;">200</span></td>
</tr>
</tbody>
</table>
<p><b>訂單表</b></p>
<table>
<tbody>
<tr>
<td><b>訂單編號</b></td>
<td><b>客戶編號</b></td>
<td><b>產品編號</b></td>
<td><b>日期</b></td>
<td><b>數量</b></td>
</tr>
<tr>
<td><span style="font-weight: 400;">O1001</span></td>
<td><span style="font-weight: 400;">C001</span></td>
<td><span style="font-weight: 400;">P01</span></td>
<td><span style="font-weight: 400;">7/26</span></td>
<td><span style="font-weight: 400;">1</span></td>
</tr>
<tr>
<td><span style="font-weight: 400;">O1002</span></td>
<td><span style="font-weight: 400;">C001</span></td>
<td><span style="font-weight: 400;">P02</span></td>
<td><span style="font-weight: 400;">7/28</span></td>
<td><span style="font-weight: 400;">2</span></td>
</tr>
<tr>
<td><span style="font-weight: 400;">O1003</span></td>
<td><span style="font-weight: 400;">C002</span></td>
<td><span style="font-weight: 400;">P02</span></td>
<td><span style="font-weight: 400;">7/27</span></td>
<td><span style="font-weight: 400;">1</span></td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">「小明」這兩個字只在客戶表裡出現過一次，訂單表只存客戶編號，不存名字。這樣做的好處是，小明改名字只要改一個地方；但想知道「小明總共花了多少錢」，得把三張表 JOIN 起來，先查出客戶編號、再對應產品單價，才能算出總金額。</span></p>
<p><span style="font-weight: 400;">如果是 OLAP 反正規化的做法，會攤平成一張寬表：</span></p>
<p><b>銷售事實表</b></p>
<table>
<tbody>
<tr>
<td><b>客戶姓名</b></td>
<td><b>城市</b></td>
<td><b>產品名稱</b></td>
<td><b>單價</b></td>
<td><b>日期</b></td>
<td><b>數量</b></td>
<td><b>小計</b></td>
</tr>
<tr>
<td><span style="font-weight: 400;">小明</span></td>
<td><span style="font-weight: 400;">台北</span></td>
<td><span style="font-weight: 400;">鍵盤</span></td>
<td><span style="font-weight: 400;">100</span></td>
<td><span style="font-weight: 400;">7/26</span></td>
<td><span style="font-weight: 400;">1</span></td>
<td><span style="font-weight: 400;">100</span></td>
</tr>
<tr>
<td><span style="font-weight: 400;">小明</span></td>
<td><span style="font-weight: 400;">台北</span></td>
<td><span style="font-weight: 400;">滑鼠</span></td>
<td><span style="font-weight: 400;">200</span></td>
<td><span style="font-weight: 400;">7/28</span></td>
<td><span style="font-weight: 400;">2</span></td>
<td><span style="font-weight: 400;">400</span></td>
</tr>
<tr>
<td><span style="font-weight: 400;">小華</span></td>
<td><span style="font-weight: 400;">高雄</span></td>
<td><span style="font-weight: 400;">滑鼠</span></td>
<td><span style="font-weight: 400;">200</span></td>
<td><span style="font-weight: 400;">7/27</span></td>
<td><span style="font-weight: 400;">1</span></td>
<td><span style="font-weight: 400;">200</span></td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">「小明」「台北」這些資訊重複出現了兩次。在正規化的世界裡，這種重複是大忌；但在這裡是刻意設計的，因為現在想問「小明總共花了多少錢」，不用 JOIN 任何表，直接把小明那幾列的「小計」加起來就好；想問「哪個城市買最多」，把「城市」欄位拿出來加總分組就好。</span></p>
<p><span style="font-weight: 400;">這種「一列代表一筆事件、允許重複」的表，在資料倉儲的世界裡叫 fact table（事實表）；像「小明」「台北」這種會重複、用來描述這筆事件的欄位，叫 dimension（維度）。</span></p>
<p><span style="font-weight: 400;">一句話總結兩者的差異：正規化把「小明」這個名字存一次、用編號互相參照，換取修改資料時的安全；反正規化把「小明」這個名字允許重複貼在每一列上，換取統計加總時不用東拼西湊查好幾張表。</span></p>
<p><span style="font-weight: 400;">這裡說的「攤平」，就是反正規化，把 Cosmos DB 裡打包好的巢狀資料，拆開重組成扁平的寬表。欄位命名清楚、預先算好常用的加總。讓後面不管是人還是 AI，都能一眼看懂、快速查詢。</span></p>
<p><span style="font-weight: 400;">下篇想接著聊：整理完的資料放好之後，該用什麼工具讓業務人員自然語言查詢，這件事該自己組一套系統，還是買現成的整合服務。</span></content></p>
<p>這篇文章 <a rel="nofollow" href="https://www.technice.com.tw/opinion/274103/">讓 Cosmos DB 的資料開口說話：從等分析師，到自然語言查詢｜專家論點【黃婉中】</a> 最早出現於 <a rel="nofollow" href="https://www.technice.com.tw">科技島-掌握科技新聞、科技職場最新資訊</a>。</p>
]]></description>
		
					<wfw:commentRss>https://www.technice.com.tw/opinion/274103/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
