Group and add in Mysql

0

Good morning, I have a table made in mysql in the following way:

___________________________________
servicio    | estatus    | cantidad
Agua Potable| ACTIVO     |   4
Agua Potable| EN PROCESO |   3
Agua Potable| RESUELTO   |   2
Agua Servida| ACTIVO     |   3
Agua Servida| INACTIVO   |   1
Agua Servida| EN PROCESO |   5
Agua Servida| RESUELTO   |   3

I need a query that groups me and totals the records in this way:

servicio    | estatus    | cantidad
Agua Potable| ACTIVO     |   4
            | EN PROCESO |   3
            | RESUELTO   |   2
Agua Servida| ACTIVO     |   3
            | INACTIVO   |   1
            | EN PROCESO |   5
            | RESUELTO   |   3

to then make a graph

I annex the code of what I have done to see if you can help me:

<?php
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
$resulta_estatus = $db->query("SELECT servicio, estatus, count(idestatus) as Cantidad FROM reporte GROUP by servicio, estatus");
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <script type="text/javascript" src="js/loader.js"></script>
  <script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);
 function drawChart() {
 var data = google.visualization.arrayToDataTable([['estatus', 'Cantidad'],
  <?php
  if($resulta_estatus->num_rows > 0){
      while($row = $resulta_estatus->fetch_assoc()){
        echo "['".$row['estatus']."', ".$row['Cantidad']."],";
      }
  }
  ?>
]);
var options = {
      title: 'Indicador de Gestion Mensual',
      hAxis: {title: 'Tipo de Servicio', titleTextStyle: {color: 'red'}}
    };

var chart = new   google.visualization.ColumnChart(document.getElementById('columchart'));

chart.draw(data, options);
}
</script>
</head>

              

    
asked by HGarcia 23.11.2017 в 17:04
source

1 answer

-1

I think the query would be

SELECT COUNT (estatus) as Total, servicio, status FROM mi_tabla GROUP BY servicio, status; // reemplazar mi_tabla por el nombre de tu tabla.

Greetings.

    
answered by 23.11.2017 в 17:52