I'm trying to use a MYSQL query to group each month and each year and the total made in that month, i have tried various times but it always seems error out.
My current query:
<table class="table table-condensed table-striped table-hover table-responsive">
<thead>
<tr>
<th>Month</th>
<th>Year</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
$p1 = DB::getInstance()->select("SELECT SUM(`pay_cost`) AS `madePerMonth` MONTH(pay_date) as month, YEAR(pay_date) as year FROM `payments` GROUP BY YEAR(pay_date), MONTH(pay_date) DESC");
?>
<?php foreach ($p1 as $r1) { ?>
<tr>
<td><b><?php echo $r1['month']; ?></b></td>
<td><b><?php echo $r1['year']; ?></b></td>
<td><b><?php echo $r1['madePerMonth']; ?></b></td>
</tr>
<?php } ?>
</tbody>
</table>
This error shows: 1.An alias was previously found. (near "month" at position 56) can anyone see the issue? any help is appreciated.