score:0

Accepted answer

Updated Answer:

If Category is dynamic, here's what you can do:

create table CATEGORY (
  ID int NOT NULL AUTO_INCREMENT,
  NAME varchar(16) NOT NULL,
  PRIMARY KEY(ID)
)

create table MONTHS (
  MONTH int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY(MONTH)
)

create table CATEGORY_SUM (
  ID int NOT NULL AUTO_INCREMENT,
  CATEGORY int NOT NULL,
  MONTH int NOT NULL,
  PRIMARY KEY(ID),
  FOREIGN KEY(CATEGORY) references CATEGORY(ID),
  FOREIGN KEY(MONTH) references MONTHS(ID)
)

Then fill your MONTHS table with all the months you need

Then you can do something like

SELECT * from CATEGORY_SUM 
RIGHT OUTER JOIN MONTHS ON CATEGORY_SUM.MONTH = MONTHS.MONTH 
order by CATEGORY_SUM.CATEGORY, CATEGORY_SUM.MONTH

I leave to you to get the actual name of the category into this query


Related Query

More Query from same tag