0

I have a table with 4 columns: ID, fieldDATE, fieldINT1, fieldINT2.

Table is like this:

ID| fieldDate | FieldINT1 | FiledINT2 |

 ===================================

 1 |  2016-01-01   | 100    |  1     |

 2 |  2016-01-08   | 200    |  1     |

 3 |  2016-02-01   | 150    |  1     |

 4 |  2016-02-05   | 400    |  2     |

 5 |  2017-01-01   | 120    |  1     |

 6 |  2017-01-21   | 123    |  1     |

 7 |  2017-02-03   |  30    |  1     |

 8 |  2018-01-01   | 123    |  1     |

 9 |  2018-01-03   |  30    |  1     |

I'd like to create a table with 12 rows, with the first column is the month name, and the other columns are sum of fieldINT1 and fieldINT2, group by month in a specific YEAR. So in my example, there will be 4 columns ( MONTH NAME, 2016, 2017, 2018) How can I do it?

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
user1903894
  • 169
  • 1
  • 1
  • 6
  • 1
    What did you try so far? – Jan Zeiseweis Jan 04 '18 at 11:35
  • Possible duplicate of [Mysql query to dynamically convert rows to columns on the basis of two columns](https://stackoverflow.com/questions/17964078/mysql-query-to-dynamically-convert-rows-to-columns-on-the-basis-of-two-columns) – Perfect Square Jan 04 '18 at 12:24
  • 1
    Is it possible that you can return the values in a result set with the columns `month`, `year` and `sum`? This way the query is pretty simple, just a normal `GROUP BY` and `SUM()` statement. – Progman Jan 04 '18 at 14:38

0 Answers0