SQL View. Select a counter ... Where

I am most confused about this, so it's best to ask the experts!

These are the strings returned by my own request.

Col1   Col2   Result
Font   Bold   a
Font   Bold   b
Font   Bold   a
Font   Italic a 

Is there a way to use the select select in the above (tabular) results to get this?

Col1  Col2   ResultA  ResultB
Font  Bold   2        1
Font  Italic 1        0

**** Update: **** Values ​​to be considered results are a and b.

ps Unfortunately, I can not publish the full table schema.

+3
source share
2 answers

Sort of:

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
+8
source
SELECT col1, col2, COUNT (result) as result1 FROM table GROUP BY col1, col2

Please explain what it should take to get 1 in the first and 0 in the second line of your example.

0

Source: https://habr.com/ru/post/1730098/


All Articles