Skip to content

[auto-build] backport-56-fd29d268d3c97fc2b4dd351905c4b481847d7542 -> release-x.56.x #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ Here's an example that counts the number of orders in the `orders` table and ins
{% raw %}
SELECT
COUNT(*) AS "Orders",
{{mb.time_grouping("Time grouping", "created_at")}} AS "Created At"
{{created_at_param}} AS "Created At"
FROM
orders
GROUP BY
{{mb.time_grouping("Time grouping", "created_at")}}
{{created_at_param}}
{% endraw %}
```

Like in all SQL groupings, you must include the parameter in both the `SELECT` and `GROUP BY` clauses. You can also use the `mb.time_grouping` function on different columns in the same query, like this:

```sql
{% raw %}
SELECT
COUNT(*) AS "Count",
{{created_at_param}} AS "Created at",
Expand All @@ -47,6 +48,7 @@ FROM
GROUP BY
{{created_at_param}},
{{trial_ends_at}}
{% endraw %}
```

Like with all parameters, you can set a default value (e.g., "month"). With time grouping parameters, you're limited to the options for the [time grouping parameter](../../dashboards/filters#time-grouping-parameter).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4860,25 +4860,27 @@ <h2 id="time-grouping-parameter-example">Time grouping parameter example</h2>
<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">SELECT</span>
<span class="k">COUNT</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="nv">"Orders"</span><span class="p">,</span>
<span class="p">{{</span><span class="n">mb</span><span class="p">.</span><span class="n">time_grouping</span><span class="p">(</span><span class="nv">"Time grouping"</span><span class="p">,</span> <span class="nv">"created_at"</span><span class="p">)}}</span> <span class="k">AS</span> <span class="nv">"Created At"</span>
<span class="p">{{</span><span class="n">created_at_param</span><span class="p">}}</span> <span class="k">AS</span> <span class="nv">"Created At"</span>
<span class="k">FROM</span>
<span class="n">orders</span>
<span class="k">GROUP</span> <span class="k">BY</span>
<span class="p">{{</span><span class="n">mb</span><span class="p">.</span><span class="n">time_grouping</span><span class="p">(</span><span class="nv">"Time grouping"</span><span class="p">,</span> <span class="nv">"created_at"</span><span class="p">)}}</span>
<span class="p">{{</span><span class="n">created_at_param</span><span class="p">}}</span>

</code></pre></div></div>

<p>Like in all SQL groupings, you must include the parameter in both the <code class="language-plaintext highlighter-rouge">SELECT</code> and <code class="language-plaintext highlighter-rouge">GROUP BY</code> clauses. You can also use the <code class="language-plaintext highlighter-rouge">mb.time_grouping</code> function on different columns in the same query, like this:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">SELECT</span>
<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">SELECT</span>
<span class="k">COUNT</span><span class="p">(</span><span class="o">*</span><span class="p">)</span> <span class="k">AS</span> <span class="nv">"Count"</span><span class="p">,</span>
<span class="k">AS</span> <span class="nv">"Created at"</span><span class="p">,</span>
<span class="k">AS</span> <span class="nv">"Trial ends at"</span>
<span class="p">{{</span><span class="n">created_at_param</span><span class="p">}}</span> <span class="k">AS</span> <span class="nv">"Created at"</span><span class="p">,</span>
<span class="p">{{</span><span class="n">trial_ends_at</span><span class="p">}}</span> <span class="k">AS</span> <span class="nv">"Trial ends at"</span>
<span class="k">FROM</span>
<span class="n">accounts</span>
<span class="k">GROUP</span> <span class="k">BY</span>
<span class="p">,</span>

<span class="p">{{</span><span class="n">created_at_param</span><span class="p">}},</span>
<span class="p">{{</span><span class="n">trial_ends_at</span><span class="p">}}</span>

</code></pre></div></div>

<p>Like with all parameters, you can set a default value (e.g., “month”). With time grouping parameters, you’re limited to the options for the <a href="../../dashboards/filters#time-grouping-parameter">time grouping parameter</a>.</p>
Expand Down