The following is the query
select a,b,count(1) count from tbl group by a,b order by a,b
which will give the output like this
a b count
=============== ===============
18 A 16
18 B 6
18 C 7
18 D 9
19 A 16
19 B 6
19 C 7
19 D 9
17 A 16
17 B 6
17 C 7
17 D 9
But I want the output in the following format based on the field b
a count1 count2 count3 count4
=============== =============== =============== ==
18 16 6 7 9
19 16 6 7 9
17 16 6 7 9
Any idea or help to achieve this?
select a,b,count(1) count from tbl group by a,b order by a,b
which will give the output like this
a b count
=============== ===============
18 A 16
18 B 6
18 C 7
18 D 9
19 A 16
19 B 6
19 C 7
19 D 9
17 A 16
17 B 6
17 C 7
17 D 9
But I want the output in the following format based on the field b
a count1 count2 count3 count4
=============== =============== =============== ==
18 16 6 7 9
19 16 6 7 9
17 16 6 7 9
Any idea or help to achieve this?
Comment