title: Aggregate logical AND / OR for columns with type 'bit'
body: <p>For the T-SQL (SQL Server 2016) <code>bit</code>  type, is there some way to achieve an aggregate equivalent of a logical AND and a logical OR? For example, with this table:</p>
  
  <pre><code>CREATE TABLE #Example       (id int, category int, isRed bit, isBlue bit)
  INSERT INTO #Example VALUES (     1,            1,         1,          1)
  INSERT INTO #Example VALUES (     2,            1,         0,          0)
  INSERT INTO #Example VALUES (     3,            1,         1,          0)
  INSERT INTO #Example VALUES (     4,            2,         0,          1)
  INSERT INTO #Example VALUES (     5,            2,         0,          1)
  INSERT INTO #Example VALUES (     6,            2,         0,          1)
  </code></pre>
  
  <p>I'd like to create a query that lists, per category, if <em>any</em> of <code>isRed</code> is set (OR), and if <em>all</em> of <code>isBlue</code> is set (AND), e.g. outputting:</p>
  
  <pre><code>category  anyRed  allBlue
         1       1        0
         2       0        1
  </code></pre>
  
  <p>That is, I'd <em>like</em> something like:</p>
  
  <pre><code>SELECT
    category,
    OR(isRed) isAnyRed,
    AND(isBlue) isAllBlue
  FROM
    #Example
  GROUP BY
    category
  </code></pre>
  
  <p>The only thing I could think of to try was:</p>
  
  <pre><code>SELECT
    category,
    MAX(isRed) isAnyRed,
    MIN(isBlue) isAllBlue
  FROM
    #Example
  GROUP BY
    category
  </code></pre>
  
  <p>Which does not work, giving the error:</p>
  
  <pre><code>Operand data type bit is invalid for max operator.
  </code></pre>
  
  <p>Similar results occur with all other aggregate functions.</p>