 <p>I am by no means an expert &mdash; when HQL stymies me, I rarely have qualms about bypassing the problem by switching to straight SQL &mdash; so I can't tell you if there is a better, more HQL-ish way to do this. But in your specific instance, where <code>B.marker</code> is always either <code>0</code> or <code>1</code>, I suppose you <em>could</em> change</p> <pre><code>COUNT(CASE WHEN B.marker = 1 THEN 1 ELSE NULL END) </code></pre> <p>to</p> <pre><code>SUM(B.marker) </code></pre> <p>and </p> <pre><code>COUNT(CASE WHEN B.marker = 0 THEN 1 ELSE NULL END) </code></pre> <p>to</p> <pre><code>COUNT(*) - SUM(B.marker) </code></pre> <p>(though you <em>may</em> also need to wrap your <code>SUM</code>s in <code>COALESCE(..., 0)</code> &mdash; I'm not sure).</p>