SQL View. Select count... Where

count, select, sql, sql-server

Solution

Something like:

SELECT Col1, Col2, 
  SUM(CASE WHEN Result=1 THEN 1 ELSE 0 END) Result1, 
  SUM(CASE WHEN Result=2 THEN 1 ELSE 0 END) Result2 
  FROM yourTable
  GROUP BY Col1, Col2

Problem

I am most confused with this one, so i d better ask the experts! These are the rows returned by a custom query of mine. ``` Col1 Col2 Result Font Bold a Font Bold b Font Bold a Font Italic a ``` Is there any way of using selecting count in the above (table) results in order getting this one? ``` Col1 Col2 ResultA ResultB Font Bold 2 1 Font Italic 1 0 ``` ****Update:****The values that should be counted as results are a and b. p.s. Unfortunately i cannot post the full schema of the table.

Original source