MySQL - how to dynamically add columns with subquery in Select clause based on date range I have the following statetment:

 Select a.Data AS Data_A,b.Data AS Data_B,
(Select Round(Sum(C.Value)) From Values c  
  Where 
  (Year(c.TimeStamp) = x) and 
  (Month(c.TimeStamp) = y)
) AS MonthYear

From Table1 a  Left Join Table2 b on (a.ID = b.ID)


Ist there any way to add a column to the select clause based on my desired range of date? (where Year(c.TimeStamp) &lt; 2019 and Month(c.TimeStamp) &lt;= 12) 

Example1 - i want to see the data for 1 month:

Select a.Data AS Data_A,b.Data AS Data_B,
(Select Round(Sum(C.Value)) From Values c  
  Where 
  (Year(c.TimeStamp) = 2018) and 
  (Month(c.TimeStamp) = 1)
) AS Jan2018

From Table1 a  Left Join Table2 b on (a.ID = b.ID)


Example2: i want to see the data for 3 months

Select a.Data AS Data_A,b.Data AS Data_B,
(Select Round(Sum(C.Value)) From Values c  
  Where 
  (Year(c.TimeStamp) = 2018) and 
  (Month(c.TimeStamp) = 1)
) AS Jan2018,
(Select Round(Sum(C.Value)) From Values c  
  Where 
  (Year(c.TimeStamp) = 2018) and 
  (Month(c.TimeStamp) = 2)
) AS Feb2018,
(Select Round(Sum(C.Value)) From Values c  
  Where 
  (Year(c.TimeStamp) = 2018) and 
  (Month(c.TimeStamp) = 3)
) AS Mar2018

From Table1 a  Left Join Table2 b on (a.ID = b.ID)


I hope my question is understandable. :)

Thank you for reading.
You must construct different queries to get 1 column of output versus 3 columns.  That is best done in your application language.  If you are trying to do it entirely in SQL, it would require a messy Stored Procedure.