Unique values
CoddyのSQLジャーニー「基礎」セクションの一部 — レッスン 4/72。
以下の表があると仮定します:
売上
| 国 | 都市 | 金額 | |
|---|---|---|---|
| 1 | ポーランド | ワルシャワ | 13 |
| 2 | ドイツ | ベルリン | 24 |
| 3 | ポーランド | カトヴィツェ | 56 |
そして、私たちは製品が販売されたすべての国を知りたいと思います。
通常のクエリを使用すると:SELECT country from sales は Poland、Germany、Poland を返します。これは求めているものではなく、Poland が 2 回繰り返されているためです。
これを解決するには、DISTINCT キーワードを使用できます:
SELECT DISTINCT country FROM salesチャレンジ
簡単利用可能なテーブルと列:
<strong>sales</strong>:<strong>coin</strong>,<strong>amount</strong>
sales テーブルで使用されたすべてのユニークなコインを取得せよ
チートシート
DISTINCT を使用して、列から一意の値を取得します:
SELECT DISTINCT column_name FROM table_nameDISTINCT なしでは、重複した値が返されます。DISTINCT ありでは、各一意の値が結果に 1 回だけ表示されます。
自分で試してみよう
このレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。
基礎のすべてのレッスン
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns