开发者

SQL View. Select count... Where

开发者 https://www.devze.com 2022-12-17 23:36 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消