mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-10 16:48:17 +08:00
21 lines
2.0 KiB
HTML
21 lines
2.0 KiB
HTML
<div class="m-bg">
|
||
<h1>SQL SELECT DISTINCT 语句</h1>
|
||
<p class="intro">SELECT DISTINCT 语句用于返回唯一不同的值。</p> <h2>SQL SELECT DISTINCT 语句</h2> <p>在表中,一个列可能会包含多个重复值,有时您也许希望仅仅列出不同(distinct)的值。</p> <p>DISTINCT 关键词用于返回唯一不同的值。</p> <h3>SQL SELECT DISTINCT 语法</h3> <div class="code notranslate"><pre><div> SELECT DISTINCT <em>column_name</em>,<em>column_name</em><br/> FROM <em>table_name</em>;</div></pre></div> <h2>演示数据库</h2> <p>在本教程中,我们将使用众所周知的 Northwind 样本数据库。</p> <p>下面是选自 "Customers" 表的数据:</p> <table class="reference notranslate">
|
||
<tr>
|
||
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
|
||
<tr>
|
||
<td>1<br/><br/>
|
||
</td> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Obere Str. 57</td> <td>Berlin</td> <td>12209</td> <td>Germany</td> </tr>
|
||
<tr>
|
||
<td>2</td> <td>Ana Trujillo Emparedados y helados</td> <td>Ana Trujillo</td> <td>Avda. de la Constitución 2222</td> <td>México D.F.</td> <td>05021</td> <td>Mexico</td> </tr>
|
||
<tr>
|
||
<td>3</td> <td>Antonio Moreno Taquería</td> <td>Antonio Moreno</td> <td>Mataderos 2312</td> <td>México D.F.</td> <td>05023</td> <td>Mexico</td> </tr>
|
||
<tr>
|
||
<td>4<br/><br/>
|
||
</td> <td>Around the Horn</td> <td>Thomas Hardy</td> <td>120 Hanover Sq.</td> <td>London</td> <td>WA1 1DP</td> <td>UK</td> </tr>
|
||
<tr>
|
||
<td>5</td> <td>Berglunds snabbköp</td> <td>Christina Berglund</td> <td>Berguvsvägen 8</td> <td>Luleå</td> <td>S-958 22</td> <td>Sweden</td> </tr>
|
||
</table>
|
||
<h2>SELECT DISTINCT 实例</h2> <p>下面的 SQL 语句仅从 "Customers" 表的 "City" 列中选取唯一不同的值。从 Company" 列中仅选取唯一不同的值:</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><div class="example_code notranslate"> SELECT DISTINCT City FROM Customers; </div></pre> </div> <div class="text-center padding-10 margin-t-5">
|
||
</div>
|
||
</div> |