How to fetch monthly attendance report for a student from mysql?
<p>I need to show monthly attendance report for a particular student from mysql table. I need result like below,</p>

<p>I have attendance table in my database which is:</p>

<pre><code>class_id ses_id sec_id student_id att_date   remarks taken
      11      1     17         13 2016-03-28       1 2016-03-28 19:22:23
      11      1     17         14 2016-03-28       1 2016-03-28 19:22:23
      11      1     17         15 2016-03-28       1 2016-03-28 19:22:23
      11      1     17         19 2016-03-28       1 2016-03-28 19:22:23
      11      1     17         20 2016-03-28       1 2016-03-28 19:22:23
      11      1     17         13 2016-03-29       1 2016-03-29 14:25:46
      11      1     17         14 2016-03-29       1 2016-03-29 14:25:46
      11      1     17         15 2016-03-29       1 2016-03-29 14:25:46
      11      1     17         19 2016-03-29       1 2016-03-29 14:25:46
      11      1     17         20 2016-04-05       0 2016-03-31 20:07:23
      10      1     36         17 2016-04-01       0 2016-04-01 08:32:21
      10      1     37         16 2016-04-01       1 2016-04-01 08:32:41
      11      1     17         17 2017-01-01       1 2016-04-01 08:52:39
</code></pre>

<p>I want to fetch data from my attendance table where <strong>remarks '1' means present</strong> like below:
I need mysql query to fetch the data like below</p>

<p><strong>Please anyone help me to write query</strong></p>

<p>My query is </p>

<pre><code>SELECT YEAR(att_date) AS y, MONTH(att_date) AS m, COUNT(DISTINCT att_date) FROM attendance WHERE class_id=11 AND student_id=15 GROUP BY y, m
</code></pre>

<p>But didn't got the expected result as below</p>

<p>For <strong>student-ID- 15</strong></p>

<pre><code>CLASS   STUDENT_ID  YEAR    MONTH   TOTAL_CLASSES   TOTAL_PRESENT

11      15      2016    April         21             20
11      15      2016    May           25             25
11      15      2016    June          30             29
11      15      2016    July          18             18
11      15      2017    January       28             28
</code></pre>