I am new to MYSQL and trying to get PIVOT of my data. I have the sample table as below link:
create temporary table temp(reqtypeid int, reqcode int);
insert into temp(reqtypeid, reqcode) values (NULL, 0);
insert into temp(reqtypeid, reqcode) values (NULL, 2);
insert into temp(reqtypeid, reqcode) values ( 1 , 0);
insert into temp(reqtypeid, reqcode) values (1 , 1);
insert into temp(reqtypeid, reqcode) values (2 , NULL);
insert into temp(reqtypeid, reqcode) values ( 2 , 0);
insert into temp(reqtypeid, reqcode) values ( 2 , 1);
insert into temp(reqtypeid, reqcode) values ( 3 , 1);
insert into temp(reqtypeid, reqcode) values ( 4 , NULL);
insert into temp(reqtypeid, reqcode) values ( 4 , 1);
https://rextester.com/PVBI7963
My expected output is:
I am not intending to pivot but for every reqtypeid, I want to find the count of reqcode=null, reqcode=0/1/2. The code that I have tried is in the link. I am unable to get the correct output. Can someone help?
