forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Yang, Tong <yangtong2@huawei.com> Co-committed-by: Yang, Tong <yangtong2@huawei.com>
52 lines
6.3 KiB
HTML
52 lines
6.3 KiB
HTML
<a name="mrs_01_24203"></a><a name="mrs_01_24203"></a>
|
|
|
|
<h1 class="topictitle1">SELECT: Querying Table Data</h1>
|
|
<div id="body8662426"><p id="mrs_01_24203__en-us_topic_0000001219230565_p17563153819224">This section describes the basic syntax and usage of the SQL statement for querying table data in ClickHouse.</p>
|
|
<div class="section" id="mrs_01_24203__en-us_topic_0000001219230565_section20934174015249"><h4 class="sectiontitle">Basic Syntax</h4><p id="mrs_01_24203__en-us_topic_0000001219230565_p25912163516"><strong id="mrs_01_24203__en-us_topic_0000001219230565_b811313582518">SELECT</strong> [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b122334015614">DISTINCT</strong>] expr_list</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p18590161453">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b624952566">FROM </strong>[<em id="mrs_01_24203__en-us_topic_0000001219230565_i2572141991319">database_name</em>.]<em id="mrs_01_24203__en-us_topic_0000001219230565_i11779153010139">table </em>| (subquery) | table_function] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b1330110124614">FINAL</strong>]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p759181610512">[SAMPLE sample_coeff]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p1959101610511">[ARRAY <strong id="mrs_01_24203__en-us_topic_0000001219230565_b761719181866">JOIN </strong>...]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p35918165510">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b535618311861">GLOBAL</strong>] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b1230114333612">ANY</strong>|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b112958351062">ALL</strong>|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b1698343617614">ASOF</strong>] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b106811541964">INNER</strong>|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b157261561868">LEFT</strong>|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b115445581464">RIGHT</strong>|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b7619204712">FULL</strong>|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b1974533771">CROSS</strong>] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b162761102711">OUTER</strong>|SEMI|ANTI] <strong id="mrs_01_24203__en-us_topic_0000001219230565_b264613181675">JOIN </strong>(subquery)|<strong id="mrs_01_24203__en-us_topic_0000001219230565_b323532518718">table </strong>(<strong id="mrs_01_24203__en-us_topic_0000001219230565_b19124531678">ON </strong><expr_list>)|(<strong id="mrs_01_24203__en-us_topic_0000001219230565_b9773153618717">USING </strong><column_list>)</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p1592162055">[PREWHERE expr]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p13598161452">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b9151164414714">WHERE </strong>expr]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p55917161356">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b82979521475">GROUP BY</strong> expr_list] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b1214511595713">WITH </strong>TOTALS]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p3595163519">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b3117574810">HAVING </strong>expr]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p1159116458">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b7551716284">ORDER BY</strong> expr_list] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b123191509818">WITH </strong>FILL] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b1969118521383">FROM </strong>expr] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b126897540817">TO </strong>expr] [STEP expr]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p146051616519">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b459795993">LIMIT </strong>[offset_value, ]n <strong id="mrs_01_24203__en-us_topic_0000001219230565_b7199161113918">BY </strong>columns]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p146031614512">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b7372023092">LIMIT </strong>[n, ]m] [<strong id="mrs_01_24203__en-us_topic_0000001219230565_b78884251599">WITH </strong>TIES]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p7601816251">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b32317841011">UNION ALL</strong> ...]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p3601416957">[<strong id="mrs_01_24203__en-us_topic_0000001219230565_b629790171112">INTO </strong>OUTFILE filename]</p>
|
|
<p id="mrs_01_24203__en-us_topic_0000001219230565_p14601516552">[FORMAT format]</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_24203__en-us_topic_0000001219230565_section1981215572420"><h4 class="sectiontitle">Example</h4><pre class="screen" id="mrs_01_24203__en-us_topic_0000001219230565_screen0660153511374"><strong id="mrs_01_24203__en-us_topic_0000001219230565_b10796104219375">-- View ClickHouse cluster information.</strong>
|
|
select * from system.clusters;
|
|
<strong id="mrs_01_24203__en-us_topic_0000001219230565_b10995726362">-- View the macros set for the current node.</strong>
|
|
select * from system.macros;
|
|
<strong id="mrs_01_24203__en-us_topic_0000001219230565_b13415114543715">-- Check the database capacity.</strong>
|
|
select
|
|
sum(rows) as "Total number of rows",
|
|
formatReadableSize(sum(data_uncompressed_bytes)) as "Original size",
|
|
formatReadableSize(sum(data_compressed_bytes)) as "Compression size",
|
|
round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes) * 100,
|
|
0) "Compression rate"
|
|
from system.parts;
|
|
<strong id="mrs_01_24203__en-us_topic_0000001219230565_b209671849153711">-- Query the capacity of the test table. Add or modify the where clause based on the site requirements.</strong>
|
|
select
|
|
sum(rows) as "Total number of rows",
|
|
formatReadableSize(sum(data_uncompressed_bytes)) as "Original size",
|
|
formatReadableSize(sum(data_compressed_bytes)) as "Compression size",
|
|
round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes) * 100,
|
|
0) "Compression rate"
|
|
from system.parts
|
|
where table in ('test')
|
|
and partition like '2020-11-%'
|
|
group by table;</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_24199.html">Common ClickHouse SQL Syntax</a></div>
|
|
</div>
|
|
</div>
|
|
|