'Google sheets - complicated group by query

I have 2 columns of data. First is for Year(2019,2020,2021...) and second is for result(Won,Lost).

A.    B
2019. Won
2019  Lost
2019. Lost
2020. Won
.....

I want to generate a view like this:

Year. Won. Lost
2019. 1.    2
2020. 2.    1
....

I have a query

=QUERY(A1:B100,"select A, B, count(B) group by A, B")

which generates a view like:

year()      count 
              0
2019.   lost. 2
2019    won   1
2020.   lost. 2
2020    won   1

How do I modify it to achieve my desired view?

Edit: I tried the pivot query given in one of the answers. Got an error. See the screenshot.

Query error

But I have figured out an ugly workaround:

=transpose(QUERY(A1:B4, "select B,count(B) group by B pivot A"))


Solution 1:[1]

=transpose(QUERY(A1:B100, "select B,count(B) group by B pivot A"))

Solution 2:[2]

try:

=QUERY(A1:B100, "select A,count(A) group by A pivot B")

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 simplfuzz
Solution 2