擅长:python、mysql、java
<blockquote>
<p>I don't want Postgres to run the same row-matching many times</p>
</blockquote>
<p>这就是<a href="https://www.postgresql.org/docs/devel/queries-table-expressions.html#QUERIES-GROUPING-SETS" rel="nofollow noreferrer">GROUPING SETS</a>功能背后的动机之一。尝试此模式:</p>
<pre><code>SELECT category, status, count(*)
FROM stats where id in (1,2)
GROUP BY grouping sets ((category),(status));
</code></pre>