Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
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>
2022-12-09 14:55:21 +00:00

52 lines
4.6 KiB
HTML

<a name="mrs_01_24203"></a><a name="mrs_01_24203"></a>
<h1 class="topictitle1">SELECT: Querying Table Data</h1>
<div id="body0000001184526341"><p id="mrs_01_24203__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__section20934174015249"><h4 class="sectiontitle">Basic Syntax</h4><p id="mrs_01_24203__p25912163516"><strong id="mrs_01_24203__b811313582518">SELECT</strong> [<strong id="mrs_01_24203__b122334015614">DISTINCT</strong>] expr_list</p>
<p id="mrs_01_24203__p18590161453">[<strong id="mrs_01_24203__b624952566">FROM </strong>[<em id="mrs_01_24203__i2572141991319">database_name</em>.]<em id="mrs_01_24203__i11779153010139">table </em>| (subquery) | table_function] [<strong id="mrs_01_24203__b1330110124614">FINAL</strong>]</p>
<p id="mrs_01_24203__p759181610512">[SAMPLE sample_coeff]</p>
<p id="mrs_01_24203__p1959101610511">[ARRAY <strong id="mrs_01_24203__b761719181866">JOIN </strong>...]</p>
<p id="mrs_01_24203__p35918165510">[<strong id="mrs_01_24203__b535618311861">GLOBAL</strong>] [<strong id="mrs_01_24203__b1230114333612">ANY</strong>|<strong id="mrs_01_24203__b112958351062">ALL</strong>|<strong id="mrs_01_24203__b1698343617614">ASOF</strong>] [<strong id="mrs_01_24203__b106811541964">INNER</strong>|<strong id="mrs_01_24203__b157261561868">LEFT</strong>|<strong id="mrs_01_24203__b115445581464">RIGHT</strong>|<strong id="mrs_01_24203__b7619204712">FULL</strong>|<strong id="mrs_01_24203__b1974533771">CROSS</strong>] [<strong id="mrs_01_24203__b162761102711">OUTER</strong>|SEMI|ANTI] <strong id="mrs_01_24203__b264613181675">JOIN </strong>(subquery)|<strong id="mrs_01_24203__b323532518718">table </strong>(<strong id="mrs_01_24203__b19124531678">ON </strong>&lt;expr_list&gt;)|(<strong id="mrs_01_24203__b9773153618717">USING </strong>&lt;column_list&gt;)</p>
<p id="mrs_01_24203__p1592162055">[PREWHERE expr]</p>
<p id="mrs_01_24203__p13598161452">[<strong id="mrs_01_24203__b9151164414714">WHERE </strong>expr]</p>
<p id="mrs_01_24203__p55917161356">[<strong id="mrs_01_24203__b82979521475">GROUP BY</strong> expr_list] [<strong id="mrs_01_24203__b1214511595713">WITH </strong>TOTALS]</p>
<p id="mrs_01_24203__p3595163519">[<strong id="mrs_01_24203__b3117574810">HAVING </strong>expr]</p>
<p id="mrs_01_24203__p1159116458">[<strong id="mrs_01_24203__b7551716284">ORDER BY</strong> expr_list] [<strong id="mrs_01_24203__b123191509818">WITH </strong>FILL] [<strong id="mrs_01_24203__b1969118521383">FROM </strong>expr] [<strong id="mrs_01_24203__b126897540817">TO </strong>expr] [STEP expr]</p>
<p id="mrs_01_24203__p146051616519">[<strong id="mrs_01_24203__b459795993">LIMIT </strong>[offset_value, ]n <strong id="mrs_01_24203__b7199161113918">BY </strong>columns]</p>
<p id="mrs_01_24203__p146031614512">[<strong id="mrs_01_24203__b7372023092">LIMIT </strong>[n, ]m] [<strong id="mrs_01_24203__b78884251599">WITH </strong>TIES]</p>
<p id="mrs_01_24203__p7601816251">[<strong id="mrs_01_24203__b32317841011">UNION ALL</strong> ...]</p>
<p id="mrs_01_24203__p3601416957">[<strong id="mrs_01_24203__b629790171112">INTO </strong>OUTFILE filename]</p>
<p id="mrs_01_24203__p14601516552">[FORMAT format]</p>
</div>
<div class="section" id="mrs_01_24203__section1981215572420"><h4 class="sectiontitle">Example</h4><pre class="screen" id="mrs_01_24203__screen0660153511374"><strong id="mrs_01_24203__b10796104219375">-- View ClickHouse cluster information.</strong>
select * from system.clusters;
<strong id="mrs_01_24203__b10995726362">-- View the macros set for the current node.</strong>
select * from system.macros;
<strong id="mrs_01_24203__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__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>