docs: LIMIT n BY modifier

This commit is contained in:
f1yegor 2017-03-01 01:52:25 +01:00 committed by alexey-milovidov
parent bb2e5cfb6c
commit d45f5f3277

View File

@ -2024,21 +2024,23 @@ If you have an ORDER BY clause with some small LIMIT after a GROUP BY, then ORDE
<h5>LIMIT N BY modifier</h5> <h5>LIMIT N BY modifier</h5>
LIMIT %%N%% BY %%COLUMN%% allows you to restrict top %%N%% rows per each group of %%COLUMN%% LIMIT %%N%% BY %%COLUMNS%% allows you to restrict top %%N%% rows per each group of %%COLUMNS%%. %%LIMIT N BY COLUMNS%% is unrelated to %%LIMIT BY%% clause. Key for %%LIMIT N BY%% could contain arbitrary number of columns and expressions.
Example: Example:
%%SELECT %%SELECT
domainWithoutWWW(URL) AS domain, domainWithoutWWW(URL) AS domain,
domainWithoutWWW(REFERRER_URL) AS referrer, domainWithoutWWW(REFERRER_URL) AS referrer,
device_type,
count() cnt count() cnt
FROM hits FROM hits
GROUP BY domain, referrer GROUP BY domain, referrer, device_type
ORDER BY cnt DESC ORDER BY cnt DESC
LIMIT 5 BY domain LIMIT 5 BY domain, device_type
LIMIT 100
%% %%
will select top 5 referrers for each domain. will select top 5 referrers for each domain - device type pair, total number of rows - 100.
<h4>HAVING clause</h4> <h4>HAVING clause</h4>