SQL View. Select count... Where
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.
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
SELECT col1, col2, COUNT( result ) as result1 FROM table GROUP BY col1, col2
Please explain what it should count to get 1 in first and 0 in second row of your example.
精彩评论