-1

I am working with line chart from amchats demo and I need to get data for each month from previous years and also that of this year from a field in my database. I've tried some queries like getting values for each month in a year by iterating through the months.

But, that's not what I need.

for ($i=12; $i > 0 ; $i--) {
$query = $conn->prepare("SELECT date_inserted FROM communications WHERE YEAR(date_inserted) = YEAR(CURRENT_DATE - INTERVAL $i MONTH) AND MONTH(date_inserted) = MONTH(CURRENT_DATE - INTERVAL $i MONTH)");
}

Btw, I need to get something like: the table below where value is the total count of data found in that month

2012-01-31, Value: 20
2012-02-28, Value : 53
...
2019-04-16, value : 32
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Cradoe
  • 106
  • 1
  • 8

1 Answers1

0

you can use this query.

 select date_inserted, count(*) as value from communications GROUP BY YEAR(date_inserted), MONTH(date_inserted);
Şafak Çıplak
  • 889
  • 6
  • 12